国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

vue watch監(jiān)控對(duì)象的簡(jiǎn)單方法示例

瀏覽:3日期:2022-10-12 08:41:13

watch的作用:監(jiān)聽vue實(shí)例上數(shù)據(jù)的變動(dòng)

示例:

queryData: {name: ’’,creator: ’’,selectedStatus: ’’,time: [],},

1、普通的watch

data() { return { frontPoints: 0 }},watch: { frontPoints(newValue, oldValue) { console.log(newValue) }}

2、數(shù)組的watch

data() { return { winChips: new Array(11).fill(0) }},watch: {winChips: {handler(newValue, oldValue) {for (let i = 0; i < newValue.length; i++) {if (oldValue[i] != newValue[i]) {console.log(newValue)}}},deep: true}}

3、對(duì)象的watch

data() {return {bet: {pokerState: 53,pokerHistory: ’local’} }},watch: {bet: {handler(newValue, oldValue) {console.log(newValue)},deep: true}}

tips: 只要bet中的屬性發(fā)生變化(可被監(jiān)測(cè)到的),便會(huì)執(zhí)行handler函數(shù);

如果想監(jiān)測(cè)具體的屬性變化,如pokerHistory變化時(shí),才執(zhí)行handler函數(shù),則可以利用計(jì)算屬性computed做中間層。事例如下:

4、對(duì)象具體屬性的watch[活用computed]

data() {return {bet: {pokerState: 53,pokerHistory: ’local’} }},computed: {pokerHistory() {return this.bet.pokerHistory}},watch: {pokerHistory(newValue, oldValue) {console.log(newValue)}}

總結(jié)

到此這篇關(guān)于vue watch監(jiān)控對(duì)象的文章就介紹到這了,更多相關(guān)vue watch監(jiān)控對(duì)象內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Vue
相關(guān)文章:
主站蜘蛛池模板: 临漳县| 隆化县| 蓝田县| 德江县| 搜索| 剑河县| 育儿| 信丰县| 工布江达县| 梁平县| 天祝| 大悟县| 志丹县| 天全县| 西昌市| 独山县| 万山特区| 舒城县| 信宜市| 汝南县| 浦江县| 黎城县| 新源县| 敦化市| 靖宇县| 塘沽区| 大兴区| 舟曲县| 兴城市| 勐海县| 开化县| 乌兰察布市| 台湾省| 承德县| 三江| 曲靖市| 横峰县| 辽阳县| 平远县| 胶州市| 南郑县|