【问题标题】:Vmodel with Vuex not bindingV 模型与 Vuex 不绑定
【发布时间】:2019-07-30 23:56:41
【问题描述】:

我遵循了使用 get 然后在计算属性中设置的模型,以使 vmodel 与 Vuex 和 <textarea> 的输入一起工作,但有些东西不起作用,我不确定它是什么。

我有:

<textarea
          class="text-area size19"
          rows="10"
          v-model="userInput"
          aria-label="With textarea"
          placeholder="The more keywords you add, the better..."
        ></textarea>

 computed: {
   userInput: {
    get() {
    return this.$store.getters.userInput;
    },
    set(value) {
    this.$store.commit("updateUserInput", value);
  }
}
}

然后在 .store 中有一个 getter 只返回值和一个像这样的突变:

updateUserInput: (state, newUserInput) => {
  state.userInput = newUserInput;
}

【问题讨论】:

  • 您能否提供更多详细信息 - 究竟发生了什么?如果您可以共享整个 store.js 文件,那么帮助您会容易得多

标签: vuex


【解决方案1】:

我的猜测是

要么:

updateUserInput: (state, newUserInput) => {
   Vue.set(state, 'userInput', newUserInput)
}

或:

getters: {
  userInput(state){return state.userInput}
},

其实

computed: {
  userInput: {
    get: funciton(){
      return this.$store.state.userInput
    },
    set: function(newVal){
       this.$store.commit('updateUserInput', newVal)
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-06
    相关资源
    最近更新 更多