如图,H5没有放在同一个vue文件是可以支持单选操作,触发radio-group的change事件,小程序中单选点击后无法取消选中,可以选中多个,且无法触发父组件中的change事件
TreeData.vue
<template>
<view>
<radio-group name="" @change="change">
<tree-dom :treeData="treeData"></tree-dom>
</radio-group>
</view>
</template>
<script>
import TreeDom from "./TreeDom.vue";
export default {
components: {
TreeDom
},
data() {
return {
treeData: [{
id: "001",
name: "男"
},
{
id: "002",
name: "女"
}]
}
},
methods: {
change(e) {
let {value} = e.detail;
console.log(value)
},
}
}
</script>
TreeDom.vue
<template>
<view class="list">
<view class="list-item" v-for="(item, index) in treeData" :key="index">
<label>
<radio :value="`${item.id}-${item.name}`" /><text>{{item.name}}</text>
</label>
</view>
</view>
</template>
<script>
export default {
name: "TreeDom",
props: {
treeData: {
type:Array,
default:[]
},
},
}
</script>
<style lang="scss">
.list{
.list-item{
padding: 10rpx 30rpx;
font-size: $uni-font-size-base;
}
}
</style>