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