Everyone knows that Vue has two-way data binding, but few people know how to turn off this function. For
example, if you want to change a value without changing the original value
Use Object.freeze(), which prevents modification of existing properties, and also means that the response system can no longer track changes.
example:
var obj = {
foo: 'bar'
}
Object.freeze(obj)
new Vue({
el: '#app',
data: obj
})
<div id="app">
<p>{
{ foo }}</p>
<!-- 这里的 `foo` 不会更新! -->
<button v-on:click="foo = 'baz'">Change it</button>
</div>
In addition, Vue also provides you with a method that can only modify the data once
v-once
By using the v-once command, you can also perform one-shot interpolation, when the data changes, the content of the interpolation will not be updated. But be aware that this affects other data bindings on that node:
<span v-once>这个将不会改变: {
{
msg }}</span>
life
All living beings suffer, but there are always some people who live happier lives, not because they have more than others, but because they have a clearer mind than others. The more open-minded you are, the more you understand that you should always be grateful and contented, and your life will become more comfortable.