小程序 · 報錯:: You are binding v-model directly...

報錯來源:

input使用for循環:bash

<input v-for="(item,index) in list" :key="index" v-model="item"/>app

實例:ide

<div class="cu-form-group" v-for="(item,index) in appData.welcomeList" :key="index" >
    <input class='radius' :name="'welcome'+index" v-model="item"/>
    <button class='cu-btn bg-red shadow-blur sm' @click="deleteWelcome(index)">
      <span class='icon-delete'></span> </button>
  </div>
複製代碼

報錯內容:

<input v-model="item">: You are binding v-model directly to a v-for iteration alias. This will not be able to modify the v-for source array because writing to the alias is like modifying a function l ocal variable. Consider using an array of objects and use v-model on an object property instead.spa

正確寫法:

<input v-for="(item,index) in list" :key="index" v-model="list[index]"/>
複製代碼

實例:code

<div class="cu-form-group" v-for="(item,index) in appData.welcomeList" :key="index" >
    <input class='radius' :name="'welcome'+index" v-model="appData.welcomeList[index]"/>
    <button class='cu-btn bg-red shadow-blur sm' @click="deleteWelcome(index)">
      <span class='icon-delete'></span> </button>
  </div>
複製代碼

不要寫成orm

<input v-model="item"> //錯的
複製代碼
相關文章
相關標籤/搜索