vue/no-computed-properties-in-data
禁止在data
中访问计算属性
为什么
在data()
中无法访问计算属性,因为它在初始化之前就会执行。
建议
不要在data()
中访问计算属性。
错误示例
vue
<script>
export default {
data() {
return {
bar: this.foo
};
},
computed: {
foo() {
//
}
}
};
</script>
<script>
export default {
data() {
return {
bar: this.foo
};
},
computed: {
foo() {
//
}
}
};
</script>
正确示例
vue
<script>
export default {
data() {
return {
bar: 'zhangshan'
};
},
computed: {
foo() {
//
}
}
};
</script>
<script>
export default {
data() {
return {
bar: 'zhangshan'
};
},
computed: {
foo() {
//
}
}
};
</script>