首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法调用Pinia选项API中的操作

无法调用Pinia选项API中的操作
EN

Stack Overflow用户
提问于 2022-07-11 17:09:55
回答 1查看 406关注 0票数 1

我正在使用Vue3选项API和Pinia。

我想从组件调用Pinia选项Api中的一个操作

组件

代码语言:javascript
复制
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

代码语言:javascript
复制
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,完全只是操作不工作!

有什么问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-12 04:44:37

这是你需要的

https://pinia.vuejs.org/core-concepts/actions.html#without-setup

简言之:

计算=> mapGetters

方法=> mapActions

您使用的是计算的mapActions,这样就不能工作了。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72942227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档