u
This commit is contained in:
1 parent
261a263180
commit
de2351e1b2
10 files changed
+269
-119
No files matched your search
@@ -6,27 +6,16 @@ import './index.scss'
|
||||
|
||||
export default defineComponent({
|
||||
name: 'AIcon',
|
||||
inheritAttrs: false,
|
||||
props: {
|
||||
icon: { type: String as PropType<string>, required: true },
|
||||
size: { type: Number, default: 16 },
|
||||
color: { type: String, default: 'currentColor' },
|
||||
spin: { type: Boolean, default: false },
|
||||
rotate: { type: Number, default: 360 },
|
||||
onClick: Function as PropType<(e: MouseEvent) => void>, // 明确 MouseEvent 类型
|
||||
},
|
||||
setup(props, { attrs }) {
|
||||
setup(props) {
|
||||
const prefixCls = getPrefixCls('icon')
|
||||
|
||||
// 安全调用 onClick
|
||||
const handleClick = (e: MouseEvent) => {
|
||||
props.onClick?.(e)
|
||||
// 如果 attrs 上也传了 onClick,做类型断言
|
||||
if (attrs.onClick) {
|
||||
(attrs.onClick as (e: MouseEvent) => void)(e)
|
||||
}
|
||||
}
|
||||
|
||||
return () => (
|
||||
<i
|
||||
class={props.spin ? `${prefixCls}-spin` : ''}
|
||||
@@ -37,10 +26,8 @@ export default defineComponent({
|
||||
'color': props.color,
|
||||
'--rotate-angle': `${props.rotate}deg`,
|
||||
}}
|
||||
onClick={handleClick}
|
||||
>
|
||||
<Icon
|
||||
{...attrs}
|
||||
icon={props.icon}
|
||||
width={props.size}
|
||||
height={props.size}
|
||||
|
||||
Reference in new issue
Block a user