<view class="cu-form-group solid-top">
<view class="title">车牌选择</view>
<picker @change="PickerChange" :value="carIndex" :range="carList">
<view class="picker">
{{form.carCode}}
</view>
</picker>
</view>
data() {
return {
carIndex:-1,//默认-1
form: {
carCode: '请选择车牌号',
},
carList: [],
};
},
PickerChange(e) {
/* 下拉选择车辆 如果点击值不存在并且数组不为0则默认第一个并选择 */
if (!e.detail.value&&this.carList.length>0) {
this.carIndex=0;
this.form.carCode = this.carList[0];
}
//如果有并且不为空则选择
else if(e.detail.value&&this.carList.length>0){
this.form.carCode = this.carList[e.detail.value];
this.carIndex=e.detail.value;
}
//否则则设为-1,并显示默认的值
else {
this.carIndex=-1;
this.form.carCode = this.carList[e.detail.value];
}
// console.log(this.carList[this.index])
},
![](https://img-blog.csdnimg.cn/3f2a5d6bcb4348518f42e7bcb528359c.png)