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

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

如何與Vue交換輸入字段?

如何與Vue交換輸入字段?

智慧大石 2023-11-12 22:10:30
click當(dāng)事件觸發(fā)時(shí),我很難交換字段。下面是我的代碼,它只是更改了一次值和名稱,但如果再次單擊它就不起作用。它也不會(huì)改變?cè)搗-model值。有人可以幫我嗎?超文本標(biāo)記語言<div id='app'>        <button @click="swapInputFields">Swap</button>  <input type="text" :name="[field1]" v-model="model1" :value="[fromCity]"><br>  <input type="text" :name="[field2]" v-model="model2" :value="[toCity]"></div>代碼查看:var app = new Vue({   el: '#app',   data: {      fromCity:'FROM',      toCity :'TO',      field1 :'name1',      field2 :'name2'   },   methods: {      swapInputFields()      {         this.fromCity = 'TO';         this.toCity ='FROM';         this.field1 = 'name2';         this.field2 ='name1';      }   }});
查看完整描述

1 回答

?
繁華開滿天機(jī)

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

從綁定中刪除括號(hào),并從輸入中刪除除和[ ]之外的所有屬性:typev-model


<button @click="swapInputFields">Swap</button>

<input type="text" v-model="fromCity"><br>

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

您只需要這些模型變量fromCity和toCity數(shù)據(jù):


data() {

   return {

      fromCity:'FROM',

      toCity :'TO'

   }

},

并像這樣交換它們:


swapInputFields()

{

   const temp = this.fromCity;

   this.fromCity = this.toCity;

   this.toCity = temp;

}

這是一個(gè)演示:

new Vue({

  el: "#app",

  data(){

     return {

        fromCity:'FROM',

        toCity :'TO'

     }

  },

  methods: {

    swapInputFields()

    {

      const temp = this.fromCity;

      this.fromCity = this.toCity;

      this.toCity = temp;

    }

  }

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id="app">

  <button @click="swapInputFields">Swap</button>

  <input type="text" v-model="fromCity"><br>

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

</div>


查看完整回答
反對(duì) 回復(fù) 2023-11-12
  • 1 回答
  • 0 關(guān)注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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