如何在Vue中创建自定义复选框。当复选框改变时,它应该调用函数。 我得到了错误“无法读取未定义的属性'id'” 和警告“在执行本机事件处理程序期间出现未处理的错误”
自定义复选框:
<template>
<div class="filter">
<input
:ref="id"
:id="id"
type="checkbox"
class="filter-checkbox"
@change="$emit('do', $emit)"
/>
<span>{{ label }}</span>
</div>
</template>
<script>
export default {
name: "Checkbox",
props: {
label: {
type: String
},
isSelected: {
type: Boolean
},
id: {
type: String
}
},
}
</script>
我想在父组件中使用它:
<Checkbox v-for="filter of filters" :key="filter.id" :label="filter.name" :id="filter.id" v-model="filter.selected" @do="mutuallyExclusive(filter.id)" />
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号