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