Home > Web Front-end > JS Tutorial > body text

How to understand the use of Vue's .sync modifier

不言
Release: 2018-06-30 16:52:48
Original
1375 people have browsed it

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(&#39;my-comp&#39;, {
    template: &#39;<p @click="increment">点我+1</p>&#39;,
    data: function() {
      return {copyFoo: this.foo}
    },
    props: [&#39;foo&#39;],
    methods: {
      increment: function() {
        this.$emit(&#39;update:foo&#39;, ++this.copyFoo);
      }
    }
  });
  new Vue({
    el: &#39;#app&#39;,
    data: {bar: 0}
  });
</script>
Copy after login

Instructions: Code< my-comp :foo.sync="bar"> will be expanded to < ;/comp> is just syntactic sugar.

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!

Related labels:
vue
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!