main.vue
对form表单进行验证
<el-main>
<el-row :span="24" justify="center" type="flex">
<el-col :span="24">
<el-form :model="input" :rules="rules" ref="input">
<el-form-item prop="keyword">
<el-input size="large" v-model="input.keyword" type="text" >
<el-button @click="onSubmit('input')" slot="append" icon="el-icon-search"></el-button>
</el-input>
</el-form-item>
<el-form-item label="Accurate Search" prop="rule">
<el-switch activate-value="true" inactivate-value="false" active-color="#13ce66" v-model="input.rule"></el-switch>
</el-form-item>
</el-form>
</el-col>
</el-row>
</el-main>首先form表单有三个属性
model 绑定的数据
rules 使用的验证规则
ref 表单的名字
在
el-form-item单个字段中进行验证prop声明需要验证的字段
提交按钮
在验证函数中传入表单的名字,也就是
ref所定义的字符串
在data中定义规则和验证函数
这里记得验证成功后要调用回调函数
callback()
绑定点击事件的函数
发起http请求
服务端解决跨域请求
在进入路由之前进行配置
前端进行post请求
参考
Last updated
Was this helpful?