vue select 選中問題

select一般用法:

 <select class="form-control" v-model="userinfo.roleId" @change="identitychecked($event)">
    <option>--請選擇--</option>
     <option v-for="li in roleLists" :value="li.roleId" :key="li.roleId">{{li.roleName}} 
     </option>
 </select>

選中以後在js中就可以根據獲取到選中項的id  啦 !!!用法: 

console.log(this.userinfo.roleId)

不過如果還想獲取到選中的 文本 怎麼辦呢?

使用 @change="identitychecked($event)"

  identitychecked(event) { 
      alert(event.target.options[event.target.options["selectedIndex"]].text) 
    },

就這樣

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章