Vue.js 是否可以访问watch()函数vue中的变量

Vue.js 是否可以访问watch()函数vue中的变量,vue.js,Vue.js,我想在我的watch()函数中访问变量asd,并清除asd间隔。我尝试了下面的代码,但它不工作。计时器低于0,所以有可能的解决方案吗 方法:{ 测试(){ 这是史提默; 如果(this.sTimer==0){ clearInterval(this.asd) } } }, 手表{ var asd=setInterval(()=>this.testing(),1000); } 你的观察者看不到任何东西!您需要提供一个数据项,它监视该数据项的更改 watch: { item: function (

我想在我的watch()函数中访问变量
asd
,并清除
asd
间隔。我尝试了下面的代码,但它不工作。计时器低于0,所以有可能的解决方案吗

方法:{
测试(){
这是史提默;
如果(this.sTimer==0){
clearInterval(this.asd)
}
}
},
手表{
var asd=setInterval(()=>this.testing(),1000);
}

你的
观察者看不到任何东西!您需要提供一个数据项,它监视该数据项的更改

watch: {
  item: function (newItem, oldItem) {
    console.log(oldItem + " changed to: " + newItem);
  }
},
此外,您可能需要将
asd
变量添加到
数据
部分

data() {
  return{
    asd = null;
  }
},
methods: {
    testing(){
        this.sTimer--;
      if(this.sTimer == 0){
        clearInterval(this.asd)
      }
    }
},
watch() {
 item: function (newItem, oldItem) {
   this.asd = setInterval(() => this.testing(), 1000);
 }
}

你的
观察者
没有观察任何东西!您需要提供一个数据项,它监视该数据项的更改

watch: {
  item: function (newItem, oldItem) {
    console.log(oldItem + " changed to: " + newItem);
  }
},
此外,您可能需要将
asd
变量添加到
数据
部分

data() {
  return{
    asd = null;
  }
},
methods: {
    testing(){
        this.sTimer--;
      if(this.sTimer == 0){
        clearInterval(this.asd)
      }
    }
},
watch() {
 item: function (newItem, oldItem) {
   this.asd = setInterval(() => this.testing(), 1000);
 }
}

你在看什么?你必须通过辩论,你在看什么?你必须通过辩论。