如何使用 Vue.js 中的方法绑定 v-model

How to bind a v-model with a method in Vue.js

我正在学习vuejs(3).

我有这个循环:

<tr v-for="index in 7" :key="index">
            <td>
              {{ index }} {{ getDayOfTheWeek ? getDayOfTheWeek(index) : null }}
            </td>
            <td>
              <input type="time" class="form-control" id="time_slot1_start" v-model="getTimeSlot1Start(index)" />
            </td>

函数 getTimeSlot1Start 声明如下:

methods: {

getTimeSlot1Start (day) {
      return this.openingHours.find(i => i.day === day).time_slot1_start
    },

当我想保存我的文件时,eslint 告诉我:

error 'v-model' directives require the attribute value which is valid as LHS vue/valid-v-model

为什么我会收到消息?不能绑定模型和函数吗?

v-model 指令是双向绑定,它接受 属性 作为值而不是方法,您可以使用 value 属性绑定该方法 @input 事件进行编辑索引指定的项目:

<input ...  :value="getTimeSlot1Start(index)" @input="setTimeSlot1Start(index)" />