【HAVENT原创】Vue 中使用 Vuex 的几种写法
首先我们在入口 store/index.js 文件中,将 Vuex 挂载到 Vue 上 import Vue from 'vue' import Vuex from 'vuex' // 根级别 import actions from './actions' // 页面级 import list from './modules/list' import detail from './modules/detail' // 功能模块级 import activity from './modules/activity' import comment from './modules/comment' Vue.use(Vuex) const store = new Vuex.Store({ actions, modules: { list, detail, activity, comment } }) export default store 请求方式一 (在独立的 js 文件中使用): import store from '../store' // 获取一个属性 const isWeChat = store.getters.isWeChat // 请求一个方法 const getCommentList = (data, callback) => { const params = {