首页 > 其他 > 详细

关于应用vue Store

时间:2020-05-11 13:16:13      阅读:39      评论:0      收藏:0      [点我收藏+]
import Vue from ‘vue‘
import Vuex from ‘vuex‘
import axaios from ‘axios‘

Vue.use(Vuex)

const store = new Vuex.Store({
  
  state: {
    info:{},
  },
 
  getters:{
    getInfo:state => state.info
  }
  
  mutations:{
    setInfo(state,info){
      state.info = info
    }
  },
  action:{
    getInfoFun(context,info){
      const info = axaios.get(‘/a/b‘)
      context.commit(‘setInfo‘, info)
      return info
    }
  }
})
 
 
==================组件中引用=================
this.$store.dispatch(‘getInfoFun‘)     //引用
this.$store.getters.getInfo()
==================组件中引用=================
 
 
 
==================main.js定义=================
import router from ‘./router‘
import store from ‘./store‘;
 
 
Vue.use(store)     //这可能是一种方法
 

new Vue({
el: ‘#app‘,
router, // 注册路由
store, // 注册store
components: {APP},
template: <App/>
})

==================main.js定义=================
 
 
 
 
 
 
 
 
 

关于应用vue Store

原文:https://www.cnblogs.com/HePandeFeng/p/12868429.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!