【vue】element-ui按钮点击后获焦颜色问题

采用自定义指令解决,监听获焦事件后让它失焦v-autoBlur

定义指令

1
2
3
4
5
6
7
8
9
// autoBlur.js
export default {
mounted(el) {
el.addEventListener('focus', () => {
el.blur()
})
},
}

1
2
3
import autoBlur from '@/directive/autoBlur.js'

app.directive('autoBlur', autoBlur)

使用指令

1
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-autoBlur>新增</el-button>