您好,登錄后才能下訂單哦!
這篇文章主要介紹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è)資訊頻道!
免責(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)容。