vuex
state.js
export const state = { infomationFill : { theInsured : { age: { defaultValue: 16 } } } } export const getters = { theInsured_age: state => { return state.infomationFill.theInsured.age.defaultValue }, // 被保人年龄 }
type.js
export const SET_MAIN_DEFAULT_DATA = 'SET_MAIN_DEFAULT_DATA' // 主险其他
action.js
// 主险其他保险期间otherInsuranceYear [types.SET_MAIN_DEFAULT_DATA] ({ commit }, obj) { commit(types.SET_MAIN_DEFAULT_DATA, obj) },
mutation.js
// 添加主险其他参数 [types.SET_MAIN_DEFAULT_DATA] (state, obj) { Vue.set(state.infomationFill.mainInsurePannel, 'defaultData', setData(obj, state.infomationFill.mainInsurePannel.defaultData)) }, // 主险交费期间 [types.MAIN_PAY_YEAR] (state, num) { state.infomationFill.mainInsurePannel.defaultData.payYear = num },
.vue中
computed: { mapGetters(['theInsured_age']), } methods:{ ...mapActions([types.SET_MAIN_DEFAULT_DATA]) } // 修改值 this[types.SET_MAIN_DEFAULT_DATA]({ copy: val }) // 获取值 this.$store.getters.theInsured_age