前端基于radio增強(qiáng)單選框組件,?下載完整代碼請(qǐng)?jiān)L問(wèn)uni-app插件市場(chǎng)地址:https://ext.dcloud.net.cn/plugin?id=12977
效果圖如下:



#
#### 使用方法
```使用方法
<!-- radioData:單選數(shù)據(jù) curIndex:當(dāng)前選擇序列 @change:?jiǎn)芜x事件 -->
<ccRadioView :radioData="items" :curIndex="current" @change="radioChange"></ccRadioView>
```
#### HTML代碼部分
```html
<template>
<view>
<!-- radioData:單選數(shù)據(jù) curIndex:當(dāng)前選擇序列 @change:?jiǎn)芜x事件 -->
<ccRadioView :radioData="items" :curIndex="current" @change="radioChange"></ccRadioView>
<button class="botBtn" type="primary" @click="submitBtnClick">完成</button>
<!-- 設(shè)置按鈕下面仍然可以滑動(dòng) -->
<view style="height: 30px;"></view>
</view>
</template>
```
#### JS代碼 (引入組件 填充數(shù)據(jù))
```javascript
<script>
import ccRadioView from '../../components/ccRadioView.vue'
export default {
components:{
ccRadioView
},
data() {
return {
items: [{
value: '1',
name: '事項(xiàng)一'
},
{
value: '2',
name: '事項(xiàng)二',
checked: ''
},
{
value: '3',
name: '事項(xiàng)三'
},
{
value: '4',
name: '事項(xiàng)四'
},
{
value: '5',
name: '事項(xiàng)五'
},
{
value: '6',
name: '事項(xiàng)六'
},
{
value: '7',
name: '事項(xiàng)七'
},
{
value: '8',
name: '事項(xiàng)八'
},
],
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 === 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>
/*每個(gè)頁(yè)面公共css */
.botBtn {
width: 90%;
margin-left: 5%;
margin-top: 80rpx;
height: 92rpx;
/* background-color: #F36526 !important; */
}
</style>
```