1.引入注册
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state:{
sortData: []
},
mutations:{
getSortData(state, listData){
state.sortData = listData
}
}
})
export default store
main.js 注册
import store from './store/index.js'
const app = new Vue({
...App,
store
})
2.某一个组件提交数据
this.$store.commit('getSortData', res[1].data)
3.另一个组件接收数据
import { mapState } from 'vuex'
computed: {
...mapState(['sortData']),
count(){
this.merchantData = this.sortData
},
网友评论