vue computed+watch的一种用法

时间:2021-06-23 17:07:55   收藏:0   阅读:0

先看代码:

<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
      }
    }
  }
}

果然是灵!

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!