vuex 使用

倾然丶 夕夏残阳落幕 提交于 2020-04-06 05:05:47
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  里可以

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!