Vue select的使用以及select设置默认选中,element select联动不能选择问题 | 您所在的位置:网站首页 › vue中获取到选中的元素 › Vue select的使用以及select设置默认选中,element select联动不能选择问题 |
Vue中select下拉框的默认选中项的三种情况_vue option默认选择_July++的博客-CSDN博客 vue中select的使用以及select设置默认选中_燕山八音的博客-CSDN博客 option 选项内容写在JS中的,通过v-for来遍历的: 通过v-model可以获取到选中的值,如果option中存在value属性,优先获取value值即coupon.id,如果不存在,则获取option的文本内容,也就是下面代码中coupon.name. 通过绑定、设置ID 获取到相应的值:this.value = JSON.stringify(this.DataList.checkId);(ID绑定为字符串类型) data:{ couponList:[ { id: 'A', name: '优惠券1' }, { id: '1', name: '优惠券2' }, { id: '2', name: '优惠券3' } ], couponSelected: '', }, {{coupon.name}} created(){ //如果没有这句代码,select中初始化会是空白的,默认选中就无法实现 this.couponSelected = this.couponList[0].id; //或者在接口中 直接获取到ID this.couponSelected = datas.couponid; }, methods:{ getCouponSelected(){ //获取选中的优惠券 console.log(this.couponSelected) } }element: {item.VersionNames}} |
CopyRight 2018-2019 实验室设备网 版权所有 |