<el-input
v-model="value"
v-focus
>
</el-input>
directives: {
// 注册一个局部的自定义指令 v-focus
focus: {
// 指令的定义
inserted(el) {
// 聚焦元素
if (el.querySelector('input')) {
el.querySelector('input').focus();
}
},
},
},
附
当使用@keyup.enter敲击enter回车执行提交表单, el组件就要用
@keyup.enter.native
, 但是当只存在一个输入框的时候from
元素需要加上@submit.native.prevent
如若不加,当你按enter之后页面会刷新地址栏还会多一个"?",当一个form
元素中只有一个输入框时,在该输入框中按下回车应提交该表单。如果希望阻止这一默认行为,可以在 标签上添加@submit.native.prevent
评论 (0)