Vue报错 Unexpected side effect in "*" computed property


export default {
    computed: {
        liveShow() {
            if (!this.liveIsClose) {
                this.$nextTick(() => {
                    // someCode
                }
                return true;
            } else {
                return false;
            }            
        }
    }
}

这时候会提示这样写有问题。计算属性只要单纯的运算,依赖某些值,得到某个值。不要做其他的操作,赋值,修改dom等。

真的需要操作就放到watch里面。

export default {
    computed: {
        liveShow() {
            if (!this.liveIsClose) {
                return true;
            } else {
                return false;
            }            
        }
    },
    watch() {
        liveShow(val) {
            if(val) {
                // someCode
            }
        }
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM