我想执行重定向,但是在发生重定向之前,我想使用store.dispatch执行操作。错误是控制台中“未定义存储”。
我尝试将整个代码行放在一个变量中,并检查是否为真,如果为null,错误消失了,但是动作从未被调用,调试器显示vue正在跳过if语句。
import Vue from 'vue'
import store from './store/index'
import Router from 'vue-router'
import Settings from './views/Settings.vue'
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/myPath',
name: 'myPathName',
component: {},
beforeEnter(to, from, next) {
//STORE is not defined
store.dispatch("path/MY_ACTION");
next({
name: "destinationPath",
})
}
}
-----------------------------------------------------------------------------
MY STORE
// STORE -> MODULES -> CONFIGURATION -> INDEX
import windowsModule from "../windows/index"
import mainDoorModule from "../maindoor/index"
import doorLeavesModule from "../doorleaves/index"
import doorModule from "../door/index"
import actions from "./actions"
import mutations from "./mutations"
export default {
namespaced: true,
modules: {
windows: windowsModule,
mainDoor: mainDoorModule,
doorLeaves: doorLeavesModule,
door: doorModule
},
state: {
configurationId: 0,
savedConfigurationsViewModel: [],
errors: {},
configurationsToSend: []
},
mutations,
actions
}
//THE ACTION I AM TRYING TO REACH INSIDE ACTIONS
// STORE -> MODULES -> CONFIGURATION -> ACTIONS
GET_DEFAULT_CONFIGURATION({ commit }) {
commit('SET_CONFIGURATION', {
//DATA
}
}
答案 0 :(得分:1)
您需要将其安装在主要组件中。然后,您通过function wpblog_add_google_fonts() {
wp_enqueue_style( ' wpblog_google_fonts ', ' https://fonts.googleapis.com/css...', false );}
add_action( 'wp_enqueue_scripts', 'wpblog_add_google_fonts' );
进行引用。阅读Vuex文档。
this.$store
export const store = new Vuex.Store({
state: {},
mutations: {},
getters: {}
})
答案 1 :(得分:0)
所以它解决了。一个Chrome错误说商店是未定义的,它在webpack中。商店已定义。 问题是动作和突变发送不匹配类型的有效载荷之间存在不匹配。
感谢所有答案,谢谢。