- elementUI 参数传递类型错误 2020-04-30
- [Vue warn]: Invalid prop: type c
- [Vue warn]: Invalid prop: type c
- [vue warn]:Invalid prop: type ch
- vue项目报错Invalid prop: type check
- [Vue warn]: Invalid prop: custom
- vue报错:[Vue warn]: Invalid prop:
- elementUI系列02:Invalid prop: type
- vue2.x props双向数据绑定
- Failed prop type: Invalid prop `
今天在重写ant design vue button 组件的时候,拦截click事件,出现的问题
问题代码
<template>
<AButton @click="clickHandle" v-bind="props">
<slot></slot>
</AButton>
</template>
<script setup lang="ts">
import type { ButtonProps } from 'ant-design-vue'
const props = withDefaults(defineProps<ButtonProps & {
/**
* 鼠标点击延迟时间,默认500
*/
delayTime?: number
}>(), {
delayTime: 500,
})
</script>
原因是v-bind直接绑定了所有属性,需要剔除onClick,增加代码
const otherProps = computed(() => Object.assign({}, props, { onClick: undefined }))
v-bind改成绑定otherProps即可
总结:
遇到这类问题主要是两个组件使用了相同属性或者事件名,透传的时候就会有问题,如果是属性可以通过inheritAttrs解决
defineOptions({
inheritAttrs: true,
})
事件就需要剔除多余属性
网友评论