久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

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

瀏覽:6日期: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)文章:
主站蜘蛛池模板: 牟定县| 宣恩县| 青龙| 保康县| 运城市| 新龙县| 博客| 安顺市| 德保县| 分宜县| 鞍山市| 通海县| 凤凰县| 黔东| 工布江达县| 宕昌县| 都昌县| 洛川县| 板桥市| 将乐县| 治县。| 贺兰县| 浙江省| 临澧县| 合江县| 仪征市| 石嘴山市| 洛隆县| 玉田县| 扬中市| 板桥市| 西盟| 嘉鱼县| 贵港市| 乌鲁木齐县| 蓬安县| 绥宁县| 陈巴尔虎旗| 山东| 汨罗市| 横山县|