第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

v-for在vue.js中不使用html元素

v-for在vue.js中不使用html元素

慕慕森 2021-04-27 17:22:51
我是Vue.js的新手我正在為輸入元素實(shí)踐準(zhǔn)備演示,這是我的代碼。的HTML<div id="inputDiv"><form action="">    <input type="text" v-model="first_name">    <input type="text" v-model="last_name">    <input type="email" v-model="email">    <div>        <input type="radio" :name="gender" v-model="gender" value="male">Male        <input type="radio" :name="gender" v-model="gender" value="female">Female    </div>    <textarea v-model="address" id="" cols="30" rows="10"></textarea>    <br>    <div v-for="hobby in hobbies">        <input type="checkbox" v-model="userHobbies" v-bind:value="hobby">{{hobby}}    </div></form></div>腳本  const inputApp = new Vue({  el: '#inputDiv',  data: {    first_name: '',    last_name: '',    email: '',    gender: 'male',    address: '',    userHobbies:[],    hobbies: ['Reading', 'Cricket', 'Cycling', 'Hiking']  }  })})在這里您可以看到,要顯示帶有標(biāo)簽的Hobby,我必須與parent進(jìn)行迭代,添加div不是我想要的,如果我會(huì)v-for在輸入元素中輸入: <input type="checkbox" v-for="hobby in hobbies" v-model="userHobbies" v-bind:value="hobby">{{hobby}}細(xì)說(shuō)是個(gè)例外[Vue警告]:實(shí)例上未定義屬性或方法“愛好”我的問(wèn)題是是否可以在不使用HTML元素的情況下對(duì)對(duì)象元素使用v-for?
查看完整描述

3 回答

?
慕姐4208626

TA貢獻(xiàn)1852條經(jīng)驗(yàn) 獲得超7個(gè)贊

將其包裝在template標(biāo)簽中,因?yàn)槟0鍢?biāo)簽不會(huì)出現(xiàn)在最終呈現(xiàn)的HTML中:


<template v-for="hobby in hobbies">

    <input type="checkbox" v-model="userHobbies" v-bind:value="hobby">{{hobby}}

</template>

甚至更好的是,改善標(biāo)記語(yǔ)義并使用標(biāo)簽標(biāo)記:


<label v-for="hobby in hobbies">

    <input type="checkbox" v-model="userHobbies" v-bind:value="hobby"> {{hobby}}

</label>


查看完整回答
反對(duì) 回復(fù) 2021-05-13
?
千萬(wàn)里不及你

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個(gè)贊

您可以在div內(nèi)添加模板,因?yàn)槟0逦闯尸F(xiàn)到DOM:


  <div id="inputDiv">

    <form action>

      <input type="text" v-model="first_name">

      <input type="text" v-model="last_name">

      <input type="email" v-model="email">

      <div>

        <input type="radio" :name="gender" v-model="gender" value="male">Male

        <input type="radio" :name="gender" v-model="gender" value="female">Female

      </div>

      <textarea v-model="address" id cols="30" rows="10"></textarea>

      <br>

      <template v-for="hobby in hobbies">

        <input type="checkbox" v-model="userHobbies" v-bind:value="hobby">

        {{hobby}}

      </template>

    </form>

  </div>


查看完整回答
反對(duì) 回復(fù) 2021-05-13
  • 3 回答
  • 0 關(guān)注
  • 675 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)