在Vue如何使用自定义多选组件?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

子组件(选项卡)
checkBoxCard.vue
<template>
<div class="checkBoxCard">
<div :class="`box ${check && 'boxCheck'}`" @click="checked(), updateData()">
{{ name }}
</div>
</div>
</template>
<script>
export default {
name: "checkBoxCard",
props: {
name: String,
checkIndex: {
type: Number,
default: null,
},
},
data() {
return {
radio: 0,
check: false,
radioName: "",
list: [],
};
},
methods: {
checked() {
if (this.radio == 1) {
this.check = false;
this.radio = 0;
} else if (this.radio == 0) {
this.check = true;
this.radio = 1;
}
},
updateData() {
if (this.radio == 1) {
this.radioName = this.name;
} else if (this.radio == 0) {
this.radioName = "";
}
this.$emit("updateSurveyData", this.radioName, this.checkIndex);
},
},
mounted() {},
created() {},
};
</script>
<style lang="scss" scoped>
.checkBoxCard {
margin-right: 15px;
display: inline-block;
margin-top: 10px;
}
.boxCheck {
color: rgba(183, 37, 37, 1);
background: bisque;
}
.box {
border: 0.55px solid #eee;
padding: 5px 10px;
font-size: 3.73333vw;
border-radius: 10px;
}
</style>