我说过10个物体组成一个数组

它们使用v-for进行迭代,以显示标签A:Inputbox,文本属性绑定为v-model.

这是它的小提琴链接.

推荐答案

我们假设您希望同时使用v-model的双向绑定和Vuex存储.

您的问题是希望Vuexstore 处于严格模式

const store = new Vuex.Store({
  // ...
  strict: true
})

所以你所有的变异都应该经过Vuexstore ,你可以在Vue中看到.js开发工具.

方法1:我们可以通过使用克隆对象和watcher提交Mutations 来避免Vuex错误.

const store = new Vuex.Store({
  strict: true,
  state: {
    formdata: [{
      label: 'A',
      text: 'some text'
    },{
    label: 'B',
    text: 'some other text'
    },{
    label: 'C',
    text: ' this is a text'
    }]
  },
  mutations: {
    updateForm: function (state, form) {
    var index = state.formdata.findIndex(d=> d.label === form.label);
      Object.assign(state.formdata[index], form);
    }
  }
});

new Vue({
  el: '#app',
  store: store,
  data () {
    return {
      //deep clone object
      formdata: JSON.parse(JSON.stringify(this.$store.state.formdata))
    };
  },
  computed: {
    formdata() {
      return this.$store.state.formdata
    }
  },
  watch: {
    formdata: function(form)
        this.$store.commit('updateForm', form);
    }
  }
})

方法2:你可以使用computed get/set来根据vuex doc个密码提交你的Mutations

computed: {
  message: {
    get () {
      return this.$store.state.obj.message
    },
    set (value) {
      this.$store.commit('updateMessage', value)
    }
  }
}

Vue.js相关问答推荐

检测Vue3/Vue-test-utils中的Vuex还原/Mutations

设置Vite Vue 3需要多个应用程序输出目录

我可以手动访问 vue-router 解析器吗?

更新 Shopware 管理 CMS 组件中的编辑器视图

过渡如何在 Vue JS 3 中的图像上工作?

vue : 多个样式的类绑定在一个

props至少应该定义它们的类型

有没有办法初始化一个保留初始 HTML 的 Vue 对象

将函数作为属性传递给 Vue 组件

如何在 vue 的 scss 中使用深度 Select 器

VueJs this.method 不是函数?如何在 Vuejs 的另一个方法中调用一个方法?

vuejs中通过变量动态调用方法

如何在 vue 3 中获取路由的参数?

Proxy代理在 Vue 3 的控制台中是什么意思?

使用 vue-router 的默认子路由

为什么 Vue.js 使用 VDOM?

使用 vuejs 动态设置 id 标签

v-if 未在计算(computed)属性上触发

Vue Router beforeRouteLeave 不会停止子组件

单击 v-select 项目时如何获取对象而不是单个值?