<uni-data-select :localdata="selectlist" @change="change" :clear="false"></uni-data-select>
请求过来的数据只能有value和text属性,一般后端返回的数据就需要我们进行遍历来转换
let option = []
const selectlist = ref([])
const cropsOption = () => {
getcrops({}).then(res => {
if (res.code === 200 && res.data) {
res.data.forEach(item => {
option.push({
value: item.id,
text: item.productName
})
})
selectlist.value = option
}
})
}
在你点击下拉列表里的文本时默认你只能拿到value属性,想要拿到文本时就需要来变通一下
const change = (e) => {
productId.value = e
const selectedCrop = selectlist.value.find(item => item.value === productId.value);
if (selectedCrop) {
const selectedCropName = selectedCrop.text;
CropName.value = selectedCropName
}
}