博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vue中同时监听多个参数
阅读量:3932 次
发布时间:2019-05-23

本文共 438 字,大约阅读时间需要 1 分钟。

vue使用watch同时监听多个参数,其中有任意一个参数发生改变时,都会被监听到

需要使用到计算属性computed监听watch

data中定义一个对象:

data(){    return{        obj:{            name:'xpf',            gender:'male',            age:24	}    }}

computed中:将需要监听的参数放入一个新变量中

computed:{    'newParams':function(){        const {name,age} = this.obj        return {name,age}    }	},

watch中:监听新的变量

watch:{    newParams:function(){        alert(1)    }},

完整代码:

	
watch同时监听多个属性
点我

 

 

转载地址:http://xrtgn.baihongyu.com/

你可能感兴趣的文章
[DP解题] 剪绳子
查看>>
[DP题解] 最长回文字符串问题
查看>>
[DP解题] 乘积最大子序列
查看>>
[DP解题] 买卖股票的最佳时间问题之三
查看>>
[DP解题] 买卖股票的最佳时间问题之四
查看>>
LeetCode刷题:125. Valid Palindrome
查看>>
LeetCode刷题:771. Jewels and Stones
查看>>
LeetCode刷题:26. Remove Duplicates from Sorted Array
查看>>
LeetCode刷题:682. Baseball Game
查看>>
LeetCode刷题:902. Numbers At Most N Given Digit Set
查看>>
LeetCode刷题:132. Palindrome Partitioning II (JAVA算法实现)
查看>>
LeetCode刷题:546. Remove Boxes —JAVA代码DP+DFS
查看>>
LeetCode刷题:925. Long Pressed Name
查看>>
LeetCode刷题:76. Minimum Window Substring (JAVA 算法实现)
查看>>
LeetCode刷题:71. Simplify Path
查看>>
LeetCode刷题:30. Substring with Concatenation of All Words
查看>>
JAVA算法:递归求解母牛问题(JAVA代码)
查看>>
JAVA算法:欧几里德算法(GCD)又称辗转相除法计算两个整数a,b的最大公约数(JAVA代码)
查看>>
JAVA算法:李白遇花喝酒游戏JAVA DFS 算法设计
查看>>
JAVA算法:括号配对问题与卡塔兰数(Catalan number)
查看>>