1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > select动态绑定vue.js

select动态绑定vue.js

时间:2023-05-18 04:32:07

相关推荐

select动态绑定vue.js

动态选项,用v-for渲染:

<select v-model="selected"><option v-for="option in options" v-bind:value="option.value">{{ option.text }}</option></select><span>Selected: {{ selected }}</span>

new Vue({el: '#demo',data: {selected: 'A',options: [{ text: 'One', value: 'A' },{ text: 'Two', value: 'B' },{ text: 'Three', value: 'C' }]}})

转自/gaoxiaoba/article/details/52763570?locationNum=14&fps=1

拿到当前选中的 option的text值

<select v-model="defaultCardId" id="select"><option v-for="item in bankCardTypeList" :value="item.bankId">{{item.bankName}} </option></select>

let select = document.getElementById('select');let index = select.selectedIndex;console.log(select.options[index].text); //当前选中的文本值

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。