vue 在vue脚手架中的js文件使用store的方法

前言:

  最近碰到一个问题需要对路由信息进行逻辑判断,但是我们的重定向文件都封装再一个js中,然后我又要使用 store 中方法,但是this.$store 显示 undefined 现在解决了 分享一下

解决方法:

  直接在当前的js中引入store

 

  

import store from '@/store';
//然后直接使用就好了
mutation:store.commit('xxx');
action: store.dispatch('xxx');
state: store.xx

  

原文地址:https://www.cnblogs.com/qlb-7/p/14335938.html