Vue form validation

In

Vue, how does the input box in the v-for loop give a non-empty prompt? click the next button. When the first behavior is empty, the raw material name cannot be empty, and when the second behavior is empty, the factory entry time cannot be empty.

HTML:

<ul>
        <li v-for="(list,id) in lists" :key="id">
          <label>{{list.title}}</label>
          <input type="text" :type="list.type" v-model="ylMsg[list.id]" >
          <i v-show = "id!=0" @click="lists.splice(id,1)" class="iconfont icon-delete del-font"></i>
        </li>
      </ul>

js:

export default {
  data () {
    return {
      ylMsg: {"": "", "": "", "": "", "": ""},
      lists: [
        {id: "", title: ""},
        {id: "", title: "", type: "date"},
        {id: "", title: ""},
        {id: "", title: ""}
      ],
    }
  }
}

how to judge this?

Dec.13,2021

<p v-show="!ylMsg[list.id]">
    {{list.title}}

change it if it is blur or click submit and reverify.


are you going to do form validation?

<ul>
        <li v-for='(list,id) in lists' :key="id">
          <label>{{list.title}}</label>
          <input type="text" :type="list.type" v-model="ylMsg[list.id]" 
          :rules="{required: true, message: list[index].title +' ', trigger: 'blur'}">
          <i v-show = "id!=0" @click="lists.splice(id,1)" class="iconfont icon-delete del-font"></i>
        </li>
      </ul>

well, the rules I wrote above uses Async Validate .


the solution of the first answer is more feasible. If you want to achieve the next step of verification, just add a variable

.
<p v-show="!ylMsg[list.id] && validated">
    {{list.title}}

validated defaults to false, and sets it to true when you click next

Menu