报错解决:Error in callback for watcher "endVal": "TypeError: this.demo.update is not a function"

在使用ivew的时候报错

Error in callback for watcher "endVal": "TypeError: this.demo.update is not a function"

全局搜索找到 this.demo.update的位置,锁定countUp.vue

报错解决:Error in callback for watcher

在这里mounted钩子中加了定时器,延时创建demo对象,导致监听this.demo.update的时候为空,找不到

报错解决:Error in callback for watcher

解决办法:在watch监听的时候也加上延迟获取,也用setTimeout( )

    mounted () {
        this.$nextTick(() => {
            setTimeout(() => {
                let res = transformValue(this.endVal);
                let endVal = res.val;
                this.unit = res.unit;
                let demo = {};
                this.demo = demo = new CountUp(this.idName, this.startVal, endVal, this.decimals, this.duration, this.options);
                if (!demo.error) {
                    demo.start();
                }
            }, this.delay);
        });
    },
    watch: {
        endVal (val) {
            let res = transformValue(val);
            let endVal = res.val;
            this.unit = res.unit;
            // this.demo.update(endVal);      //之前的方法
          
            this.$nextTick(() => {    //修改之后
              setTimeout(() => {
                this.demo.update(endVal);
              }, this.delay);
            });
        }
    }

 

 

你可能感兴趣的:(Vue)