select
<view>
<u-select v-model="show" mode="single-column" :list="list" @confirm="confirm"></u-select>
<u-button @click="show = true">打开</u-button>
</view>
<script>
onMounted(() => {
// TODO 完善流程
loadCompanyInfo()
}
// 弹出控件
const show = ref(false);
// 这种情况需要指定range-key为cateName,否则组件不知道该显示对象的哪个属性
const list = ref([]);
// const selected = ref()
// 选中后的方法回调 TODO: 自定义逻辑处理
const confirm = (selected:any) => {
console.log("点击确切换之后的值",selected[0]);
}
const loadCompanyInfo = async () =>{
const customerId = user.value.id
try {
const response :any = [{businessTaxNumber: "123456789032323", clientId: 2023045, ctype: 1, id: 55,name: "测试员"}];
// list.value = result
console.log("Companys-Result:",response)
// 将请求后的值赋值给list
list.value = response.map((item: { id: any; name: any; }) => ({
// value ,label
value: item.id,
label: item.name
}));
}catch (err:any) {
console.log(err);
if(err.errCode === 0){
Toast.show('请稍后重新尝试!');
}
}
}
</script>
效果图