我有两个使用 component 元素展示的动态组件。
<keep-alive>
<component :is="activeOption" :resources="resources" @resourceAdded="addToList"></component>
</keep-alive>
其中一个组件需要道具资源,而另一个则发出自定义事件resourceAdded。一切正常,除了我收到错误消息“Extraneous non-emits event...”和“Extraneous non-emits props...”,我理解这是因为它也在尝试传递道具并从组件发出自定义事件没有指定道具或发射。我怎样才能解决这个问题而不必在两个组件中指定发射和道具?或者这只是这样做的方法吗?
FIRST COMPONENT - 只发射
<script>
export default {
emits: ['resourceAdded'],
// props: {
// resources: {
// type: Array,
// required: true
// }
// }, NO PROPS ERROR IF THIS IS SPECIFIED
data() {
return {
errorMsg: false
}
},
methods: {
addNewResource() {
const name = this.$refs.name.value
const description = this.$refs.description.value
const link = this.$refs.link.value
if(name === '' || description === '' || link === ''){
this.errorMsg = true
}else{
this.$emit("resourceAdded", name, description, link)
}
}
}
}
</script>
第二个组件 - 只需要道具
<script>
export default {
props: {
resources: {
type: Array,
required: true
}
},
// emits: ['resourceAdded'] NO EMITS ERROR IF THIS IS SPECIFIED
}
</script>