Vue之监听watch用法

Vue.component('my-component', {
            data: function(){
                return {
                    myValue1: 'abc',
                    myValue2: 123
                }
            },
            template: `
                <div>
                    <input type="text" v-model="myValue1" />
                    <input type="text" v-model="myValue2" />
                    <p>{{myValue1}}</p>
                    <p>{{myValue2}}</p>
                </div>
            `,
            watch: {
                myValue1: function(){
                    console.log('myValue1 is updated as ' + this.myValue1);
                },

                myValue2: function(){
                    console.log('myValue2 is updated as ' + this.myValue2);
                }
            }
        })
posted @ 2020-12-12 16:53  #Friday  阅读(124)  评论(0)    收藏  举报