前端基于radio增強單選框組件, 下載完整代碼請訪問uni-app插件市場地址:https://ext.dcloud.net.cn/plugin?id=12977
效果圖如下:



#
#### 使用方法
```使用方法
<!-- radioData:單選資料 curIndex:當前選擇序列 @change:單選事件 -->
<ccRadioView :radioData="https://www.cnblogs.com/ccVue/p/items" :curIndex="current" @change="radioChange"></ccRadioView>
```
#### HTML代碼部分
```html
<template>
<view>
<!-- radioData:單選資料 curIndex:當前選擇序列 @change:單選事件 -->
<ccRadioView :radioData="https://www.cnblogs.com/ccVue/p/items" :curIndex="current" @change="radioChange"></ccRadioView>
<button type="primary" @click="submitBtnClick">完成</button>
<!-- 設定按鈕下面仍然可以滑動 -->
<view style="height: 30px;"></view>
</view>
</template>
```
#### JS代碼 (引入組件 填充資料)
```javascript
<script>
import ccRadioView from '../../components/ccRadioView.vue'
export default {
components:{
ccRadioView
},
data() {
return {
items: [{
value: '1',
name: '事項一'
},
{
value: '2',
name: '事項二',
checked: ''
},
{
value: '3',
name: '事項三'
},
{
value: '4',
name: '事項四'
},
{
value: '5',
name: '事項五'
},
{
value: '6',
name: '事項六'
},
{
value: '7',
name: '事項七'
},
{
value: '8',
name: '事項八'
},
],
current: 0,
};
},
onLoad(e) {
let tmpObj = {};
if (typeof(e.obj) === 'string') {
tmpObj = JSON.parse(e.obj);
// 查找元素位置
this.current = this.items.findIndex((el) => {
return el.name === tmpObj.name
});
}
console.log("序列 = " + this.current);
console.log("正向傳值 = " + JSON.stringify(tmpObj));
},
methods: {
radioChange: function(evt) {
for (let i = 0; i < this.items.length; i++) {
if (this.items[i].value =https://www.cnblogs.com/ccVue/p/== evt.target.value) {
this.current = i;
break;
}
}
},
submitBtnClick: function(e) {
console.log("選中的條目 = " + JSON.stringify(this.items[this.current]));
this.$eventHub.$emit('fire', this.items[this.current]);
uni.navigateBack({
delta:1
})
}
}
};
</script>
```
#### CSS
```CSS
<style>
/*每個頁面公共css */
.botBtn {
width: 90%;
margin-left: 5%;
margin-top: 80rpx;
height: 92rpx;
/* */
}
</style>
```
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/555392.html
標籤:Html/Css
下一篇:返回列表
