我使用模块化 vuex 商店,因为应用程序的每个模块都有自己的商店,我想执行我的 vuex 商店的动作,创建状态、突变和动作,但是当我在视图中执行动作时出现错误:属性' loadItems' 类型不存在'{方法:{ loadItems:ActionMethod;}; 挂载():无效;}
索引.vue:
<template>
<h1> table page </h1>
</template>
<script lang="ts">
// import store from "@/modules/table/store";
import { mapActions } from 'vuex';
export default {
methods: {
...mapActions([
'loadItems'
])
},
mounted (){
this.loadItems();
}
}
</script>
存储/索引.ts:
import { createStore } from 'vuex'
import axios from 'axios'
export default createStore({
state: {
items: [],
},
mutations: {
SET_Item (state, items) {
state.items = items
}
},
actions: {
loadItems ({ commit }) {
axios
.get('http://127.0.0.0/api/vendor/index/', {
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJpc3NhbSIsImlhdCI6MTYzMjEyNjQ2'
},
})
.then(response => response.data)
.then(items => {
console.log('items is:',items);
commit('SET_Items', items)
})
}
},
});
垫片-vuex.d.ts:
/* eslint-disable */
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}