问题描述
iView下的表单,例如登录表单,开发需求是填写完成表单后,按键盘上的回车需要自动调用Button的Submit方法(就是按回车和按Button的@click方法是一样的)
实现
实现关键点:
加上 @keydown.native.enter.prevent='someMethod'
<Form ref="loginForm" :model="loginForm" @keydown.native.enter.prevent="loginClicked" inline>
    <FormItem>
        <Input type="text" v-model="loginForm.username" placeholder="输入登录账号">
            <Icon type="ios-person-outline" slot="prepend"></Icon>
        </Input>
    </FormItem>
    <FormItem>
        <Input type="password" v-model="loginForm.password" placeholder="输入密码">
            <Icon type="ios-lock-outline" slot="prepend"></Icon>
        </Input>
    </FormItem>
    <FormItem>
        <Button type="primary" @click="handleSubmit()">登录</Button>
    </FormItem>
</Form>
handleSubmit() {
    console.log('login button clicked');
}
试过其他的方式,例如:
@submit.native.prevent="handleSubmit()"
v-on:submit.prevent="handleSubmit"
均没有效果

文章评论