溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

vue中select二級聯(lián)動第二級默認(rèn)選中第一個option值的示例分析

發(fā)布時間:2021-07-23 13:46:11 來源:億速云 閱讀:304 作者:小新 欄目:web開發(fā)

這篇文章主要介紹vue中select二級聯(lián)動第二級默認(rèn)選中第一個option值的示例分析,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

當(dāng)二級聯(lián)動比如選擇國家的時候,希望選中一個國家的時候后面城市默認(rèn)選中第一個城市,則給國家的select加一個@change事件就可以了

<div class="inputLine">
  <span>所在區(qū)域</span>
  <select name="" v-model="countryName" @change="selectCountry">
  <option :value="item" v-for="(item,index) in area">
  {{item.country}}
  <svg class="icon icon-arrow-bottom" aria-hidden="true">
  <use xlink:href="#icon-arrow-bottom" rel="external nofollow" rel="external nofollow" ></use>
  </svg>
  </option>
  </select>
  <select name="" v-model="cityName">
  <option :value="item" v-for="(item,index) in countryName.city">
  {{item}}
  <svg class="icon icon-arrow-bottom" aria-hidden="true">
  <use xlink:href="#icon-arrow-bottom" rel="external nofollow" rel="external nofollow" ></use>
  </svg>
  </option>
  </select>
 </div>
data
  countryName:{},
  cityName:"請選擇城市",
  area:[
   {
   "country":"美國",
   "city":[
    "紐約",
    "洛杉磯",
    "舊金山",
    "西雅圖",
    "波士頓",
    "休斯頓",
    "圣地亞哥",
    "芝加哥",
    "其它",
   ]
   },
   {
   "country":"加拿大",
   "city":[
    "溫哥華",
    "多倫多",
    "蒙特利爾",
    "其它"
   ]
   },
   {
   "country":"澳大利亞",
   "city":[
    "悉尼",
    "墨爾本",
    "其它"
   ]
   },
   {
   "country":"新加坡",
   "city":[
    "新加坡"
   ]
   },
   /*{
   "country":"中國",
   "city":[
   "北京市",
   ]
   },*/
  ],

methods:

selectCountry(value){
  this.cityName=this.countryName.city[0];
  },

以上是“vue中select二級聯(lián)動第二級默認(rèn)選中第一個option值的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI