0

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

And the function getTimeSlot1Start is declared like that:

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' directives require the attribute value which is valid as LHS vue/valid-v-model

Why do I get message? Is it not possible to bind a model with a function?

1
  • What's supposed to happen when the user types in the input? What do you want to set? If you do want to set something, you should use a computed with getter and setter. Commented Dec 3, 2020 at 19:22

1 Answer 1

2

v-model directive is two-way binding which accepts a property as value not a method, you could bind that method using value attribute @input event to edit the item specified by the index :

<input ...  :value="getTimeSlot1Start(index)" @input="setTimeSlot1Start(index)" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.