废话不多说上代码
vuex
const state = { value: 1 }; const mutations = { SET_VALUE: (state, value) => { state.value= value; }, }; const actions = {}; const getters = { value: state => state.value, }; export default { namespaced: true, state, getters, mutations, actions };页面
<template> <div> <el-input v-model="values"/> </div> </template> <script> import { mapGetters, mapActions, } from 'vuex'; export default { name: '' computed: { ...mapGetters({ value: 'equipmentRepair/equipment_repair/value', }), values: { get() { return this.value }, set(val) { this.SET_VALUE(val); } } }, methods: { ...mapMutations({ SET_VALUE: 'equipmentRepair/equipment_repair/SET_VALUE' }) } }搞定