How to bind v-model to methods in Vue.js
P粉445750942
P粉445750942 2023-11-05 16:36:26
0
1
455

I'm learning vuejs(3).

I have this loop:

<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>

The declaration of function getTimeSlot1Start is as follows:

methods: {

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

When I want to save my file, eslint tells me:

Error 'v-model' directive requires a valid attribute value as LHS vue/valid-v-model

Why do I receive this message? Can't bind model to function?

P粉445750942
P粉445750942

reply all(1)
P粉590929392

v-model The directive is two-way binding, it accepts a property as a value instead of a method, you can use the value property and @input Event binding this method to edit the item at the specified index:

<input ...  :value="getTimeSlot1Start(index)" @input="setTimeSlot1Start(index)" />
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!