<van-form validate-first validate-trigger="onSubmit" @submit="saveResume" :show-error-message="false">
<van-field v-model="mobile" name="手机号" label="手机号" placeholder="请填写手机号" required
:rules="[{ required: true, message: '请填写手机号' }]">
<template Slot="button">
<van-button size="small" type="info" @click.stop="getInfoResume">获取已上传简历</van-button>
</template>
</van-field>
<div style="margin: 16px;">
<van-button round block type="info" native-type="submit">提交</van-button>
</div>
</van-form>
一开始我选择在事件中加上.stop来阻止,但发现并没有用
原因
浏览器中 button 标签 type 属性的默认值为submit,导致触发表单提交。
知道原因就很好解决这个问题了,我们把type属性设置为其他类型,就不会触发表单提交
<van-button size="small" type="info" native-type='button' @click.stop="getInfoResume">获取已上传简历</van-button>
注意是 native-type=‘button’
并且事件中也要加上 .stop 来阻止其冒泡