我正在使用Vue3选项API和Pinia。
我想从组件调用Pinia选项Api中的一个操作
组件
import { mapActions } from "pinia";
import { useTableStore } from "../../../stores/table";
export default {
name: "LoggingForm",
data() {
return {
login: {
username: "",
password: "",
serverhost: "",
},
};
},
methods: {
submit(){
this.getData(this.login)
}
},
computed: {
...mapActions(useTableStore, ["getData"]),
},
};这是store/table.js
import { defineStore } from 'pinia'
import authService from "@/api/auth.js";
export const useTableStore = defineStore({
id: 'table',
state: () => ({
table: []
}),
getters: {
headers: (state) => state.table[0],
body: (state) => state.table.slice(1)
},
actions: {
async getData1(data) {
// do something
}
},
}
})但我知道这个错误

我可以使用、state、和getter,完全只是操作不工作!
有什么问题吗?
发布于 2022-07-12 04:44:37
这是你需要的
https://pinia.vuejs.org/core-concepts/actions.html#without-setup
简言之:
计算=> mapGetters
方法=> mapActions
您使用的是计算的mapActions,这样就不能工作了。
https://stackoverflow.com/questions/72942227
复制相似问题