触发监听执行多个方法

使用数组可以设置多项,形式包括字符串、函数、对象。

export default {
    
    
    data: {
    
    
        name: 'dongyu'
    },
    watch: {
    
    
        name: [
            'sayName1',
            function(newVal, oldVal) {
    
    
                this.sayName2()
            },
            {
    
    
                handler: 'sayName3',
                immaediate: true
            }
        ]
    },
    methods: {
    
    
        sayName1() {
    
    
            console.log('sayName1==>', this.name)
        },
        sayName2() {
    
    
            console.log('sayName2==>', this.name)
        },
        sayName3() {
    
    
            console.log('sayName3==>', this.name)
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_42931285/article/details/124396014