【问题标题】:Using get/set Computed property with mapState, mapMutation in Vuex在 Vuex 中使用带有 mapState、mapMutation 的 get/set Computed 属性
【发布时间】:2019-02-23 08:44:52
【问题描述】:

我使用名为main 的 Vuex 模块具有以下计算属性:

computed: {
  foo: {
    get(){
      return this.$store.state.main.foo;
    },
    set(value) {
      this.$store.commit("main/foo", value);
    }
  }
}

我想使用get/set 模式,因为我想使用v-model="foo"。必须直接与$store 交谈非常冗长。有没有更简单的方法使用mapStatemapMutation 甚至createNamespacedHelpers

【问题讨论】:

    标签: javascript vue.js vuex computed-properties v-model


    【解决方案1】:

    我建议您尝试 vuex-map-fields 模块,该模块包含一个 mapFieldshelper 方法,可帮助您动态设置 getter 和 setter。

    【讨论】:

      猜你喜欢
      • 2018-01-17
      • 1970-01-01
      • 2016-08-07
      • 2010-09-19
      • 2015-09-03
      • 2019-03-27
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      相关资源
      最近更新 更多