【发布时间】:2021-07-06 18:45:29
【问题描述】:
我已将全新版本的 Vuex 安装到 laravel/vue 设置中
我将商店导入 app.js
import store from './store';
然后我在这里使用它
const app = new Vue({
el: '#app',
store,
components: { App },
router
});
然后在我的 store/index.js 文件中
// import dependency to handle HTTP request to our back end
import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';
//load Vuex
Vue.config.devtools = true;
Vue.use(Vuex);
//to handle state
const state = {
videos: [],
test: ''
}
//to handle state
const getters = {}
//to handle actions
const actions = {
getVideos({commit}) {
axios.post('https://jsonplaceholder.typicode.com/posts')
.then(response => {
commit('SET_POSTS', response.data)
})
}
}
//to handle mutations
const mutations = {
SET_POSTS(state, payload) {
state.videos = payload
}
}
//export store module
export default {
state,
getters,
actions,
mutations
}
我认为运行 npm run watch 并构建它,我收到以下错误
'未检测到 Veux 存储'
还有
this.$store.dispatch('getVideos');
错误 [Vue 警告]:挂载钩子错误:“TypeError: this.$store.dispatch is not a function”
【问题讨论】:
-
奇怪的错误似乎有错字
-
在 vue 开发工具中对不起