vue computed+watch的一种用法

先看代码:

<el-checkbox v-model="file" :true-label="1" :false-label="0">选择</el-checkbox>

data(){
return{
file: 0
}
}

定义了一个多选框的变量,但是调接口时取到的值总有问题,于是用到了下面的写法:

computed:{
  fileChange(){
    return this.file
  }
},
watch:{
  fileChange:{
    handler(newVal, oldVal){
      this.params={
        file:newVal
      }
    }
  }
}

果然很灵!

posted @ 2021-06-23 11:25  ZJTL  阅读(75)  评论(0编辑  收藏  举报