import Vue from 'vue'
import Vuex from 'vuex'
const state = {
isLogin: true,
dialogVisible: false,
detail: false,
routes: {},
insurList: [],
insurOption: [],
barTitle: '',
reason: '', //费因名称
ysShow: false,
questionPageNo: 1
}
const mutations = {
// 改变state里的数据,
setReason(store, res) {
state.reason = res
},
}
const actions = {
getInsue(context) {
return new Promise((resolve, reject) => {
Vue.axios.get(`/remotes/productList`).then(res => {
let arr1 = []
const arr = []
res.detail.map(res => {
const obj = {
id: res.insType,
productName: Obj.insurType[res.insType],
children: res.productList
}
arr.push(obj)
arr1 = [...arr1, ...res.productList]
})
context.commit('setInsue', { arr, arr1 })
resolve()
})
})
},
//获取费因下拉选项数据
getReason(context) {
Vue.axios.get(`/remotes/productList`).then(res => {
context.commit('setReason', 1)
})
}
}
export default new Vuex.Store({
state,
getters,
mutations,
actions,
modules: {
footer: Footer
}
})
computed: {
...mapState(['reason'])
},
mounted() {
this.$store.dispatch('getReason')
this.id = this.$route.query.id
this.getData()
console.log(this.reason, 222222)
this.$nextTick(() => {
console.log(this.reason, 222222)
})
},
updated() {
console.log(this.reason, 222222)
},
munted 里拿不到数据 updated 里可以
来源:oschina
链接:https://my.oschina.net/u/4004801/blog/3218058