如何解决elementUI中按钮点击不失焦问题

139 阅读1分钟

废话不多说直接上代码,跟el-buttton一样使用只是换一个标签名 (直接将代码复制到一个组件中即可)

主要代码为 @mousedown="event=>event => event.preventDefault()"

<template>
	<el-button @mousedown="$event => $event.preventDefault()" v-bind="$attrs">
		<slot></slot>
	</el-button>
</template>
<script setup lang="ts" name="EButton">
type btnType = "primary" | "success" | "warning" | "danger" | "info";
interface paramsItem {
	label?: string;
	value?: string;
	icon?: string;
	type?: btnType;
}

interface ParamsProps {
	params?: paramsItem;
}


const props = withDefaults(defineProps<ParamsProps>(), {
	params: () => ({
		label: "默认",
		value: "default",
		icon: "",
		type: "primary"
	})
});
</script>