我有一个使用 Vue 3 和 Vuex 的项目。这是我第一次使用 Vue 3。我似乎无法在 Vue 3 项目的 Setup 方法中了解如何访问 Vuex。
我有一个特征对象。这是由 Childcomponent 使用 featureSelected 方法设置的。首先,在我的设置中,我使用 useStore 创建了一个存储常量;从 import { useStore } from "vuex";
. 然后在 featureSelected 函数中,我在这个 store 对象上调用 dispatch 函数store.dispatch("setPlot", { geometry: newFeature });
。
我不断收到一个错误消息,告诉我 store 对象上不存在 dispatch 函数:Uncaught TypeError: store.dispatch is not a function
。
setup() {
const store = useStore;
const feature = ref();
const featureSelected = (newFeature) => {
feature.value = newFeature;
store.dispatch("setPlot", { geometry: newFeature });
};
return { feature, featureSelected };
},