Vue使用watch监听数组或对象

admin3年前vue507

1、普通的watch

1
2
3
4
5
6
7
8
9
10
data() {
    return {
        frontPoints: 0  
    }
},
watch: {
    frontPoints(newValue, oldValue) {
        console.log(newValue)
    }
}

2、数组的watch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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、对象的watch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
data() {
  return {
    bet: {
      pokerState: 53,
      pokerHistory: 'local'
    } 
    }
},
watch: {
  bet: {
    handler(newValue, oldValue) {
      console.log(newValue)
    },
    deep: true
  }
}


相关文章

vue-element动态生成的表单检验使用validator属性,直接写在el-form-item

https://blog.csdn.net/qq_40052817/article/details/89184153...

防懂车帝车型对比功能

<!DOCTYPE html> <html> <head>     <meta http...

elementui tooltip内容换行设置

https://blog.csdn.net/m0_67841039/article/details/131791490...

vue elementui动态生成表格数据

<el-table :data="tableData" border class="mb30">       ...

vue-element-admin 三级路由

vue-element-admin 三级路由

三级路由的设置非常简单,不过不知道其原理就会不知道是如何设置的。vue-element-admin自带的有嵌套路由,不过他的嵌套路由有一个套路,那就是二级路由页面下有个<router-view...

vscode搭建vuecli

安装nodejs https://nodejs.org/en/download/ d:cd nodejsnode --version打开vscode终端,npm install -g vue-clic...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。