Home  >  Article  >  Web Front-end  >  There are several values ​​of bind variables in Vue and methods to prevent them from changing (detailed tutorial)

There are several values ​​of bind variables in Vue and methods to prevent them from changing (detailed tutorial)

亚连
亚连Original
2018-06-02 11:57:152633browse

Now I will share with you an article about the values ​​​​of several binding variables in Vue and the methods to prevent them from changing. It has a good reference value and I hope it will be helpful to everyone.

1. Object.freeze(obj) statement

obj={ 
 foo:"nan" 
} 
Object.freeze(obj);

After using this statement to fix a variable, subsequent changes to this variable will be invalid. and report an error in the console.

2. v-once element binding

<span>{{msg}}</span>

When the msg data changes, the span content will also change immediately, but if

<span v-once>{{msg}}</span>

If v-once binding is added, even if the msg in the data changes, the content in the span will not change accordingly. But this does not prevent data from changing, but only binds an html element so that it does not change.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Vue.js dynamically assigns value to img's src

Example of defining your own angular time component based on datepicker

vue filter filter instance detailed explanation

The above is the detailed content of There are several values ​​of bind variables in Vue and methods to prevent them from changing (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn