This article mainly introduces how to understand the use of Vue's .sync modifier. The content is quite good. I will share it with you now and give it as a reference.
This article introduces the use of Vue's .sync modifier, share it with everyone, and leave a note for yourself
Case
<p id="app"> <p>{{bar}}</p> <my-comp :foo.sync="bar"></my-comp> <!-- <my-comp :foo="bar" @update:foo="val => bar = val"></my-comp> --> </p> <script> Vue.component('my-comp', { template: '<p @click="increment">点我+1</p>', data: function() { return {copyFoo: this.foo} }, props: ['foo'], methods: { increment: function() { this.$emit('update:foo', ++this.copyFoo); } } }); new Vue({ el: '#app', data: {bar: 0} }); </script>
Instructions: Code< my-comp :foo.sync="bar"> will be expanded to
The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
About vue virtual dom patch source code analysis
v-for loads local static images in vue Method
Introduction to using Vue to dynamically generate a form
The above is the detailed content of How to understand the use of Vue's .sync modifier. For more information, please follow other related articles on the PHP Chinese website!