【发布时间】:2021-03-22 10:54:46
【问题描述】:
vuejs 中不允许在计算对象内声明属性(get() 和 set())吗?
代码有效,但是 vscode 显示大量红色,请参阅屏幕截图以供参考。
我不确定是vuejs还是vscode触发了错误。
Farmer.js 组件
computed: {
...mapState("farmers", ["crud_step"]),
normal_data(){ //this works
return 'test';
},
step: { //this also works but this line causes an error display
get() {
return this.crud_step;
},
set(value) {
return this.SET_CRUD_STEP(value);
}
},
},
farmer.js 商店
const state = {[![enter image description here][1]][1]
crud_step: 1,
...
};
const mutations = {
SET_CRUD_STEP(state, value){
state.crud_step = value;
},
...
};
注意:eslint 已禁用
回购链接:https://github.com/juanPao/acms/blob/main/src/components/Farmers/FarmerCreate.vue
【问题讨论】:
-
提供minimal reproducible example 重现错误。如果您需要类似节点的多文件编辑器并且只包含最少量的代码来重现错误,请使用 codesandbox.io。代码图片没用。只有代码有用。提供足够的信息以使问题可重现,而您还没有这样做。
标签: vue.js visual-studio-code vuex