uni-data-select的多选
时间: 2023-12-19 17:45:14 浏览: 258
uni-data-select的多选功能可以通过设置v-model为一个数组来实现。在选择项发生变化时,所选的数据将会保存在v-model所绑定的数组中。根据引用中的示例代码,你可以按照以下步骤来实现多选功能:
1. 在data中声明一个数组变量,用于保存所选的数据:
```javascript
data() {
return {
formData: {
femMerchantsClassificationId: [] // 用于保存多选结果的数组
},
range: []
}
}
```
2. 在uni-data-select标签中添加v-model属性,将其绑定到formData中的数组变量上:
```html
<uni-data-select v-model="formData.femMerchantsClassificationId" :localdata="range" @change="change"></uni-data-select>
```
3. 当下拉框内容调用后端接口时,通过遍历后端返回的数据,将每个选项的id和名称添加到range数组中:
```javascript
success: (res) => {
const All = res.data
let myrange = []
All.forEach((val, index) => {
myrange.push({
value: val.femMerchantsClassificationId, // 选项id
text: val.femMerchantsClassificationName // 选项名称
})
})
this.range = myrange
}
```
现在,你就可以通过选择uni-data-select中的选项来实现多选功能了。所选的数据将会保存在formData.femMerchantsClassificationId数组中。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [uni-app多选select组件,兼容多平台小程序、H5](https://blog.csdn.net/qq_41887214/article/details/120855815)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *3* [uniapp 下拉框效果使用 uni-data-select标签](https://blog.csdn.net/2301_76882889/article/details/130267707)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文