前端基于radio增強(qiáng)單選框組件

前端基于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>

```

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容