Home  >  Article  >  Web Front-end  >  How to understand the use of Vue’s .sync modifier

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

不言
不言Original
2018-06-30 16:52:481378browse

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>

Instructions: Codeaefc865c24cdf163192976ae986e7beb0337b061791f03922305036e30242818 will be expanded to d1e856a878a584fd29485ade05c8185f bar = val">< ;/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!

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