vue实现业务提交审核
Vue 实现业务提交审核功能
数据绑定与表单验证
使用 Vue 的 v-model 实现表单数据双向绑定,结合 Vuelidate 或 Element UI 的表单验证功能确保提交数据合法性。示例代码:
<template>
<el-form :model="form" :rules="rules" ref="submitForm">
<el-form-item label="业务名称" prop="name">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="审核内容" prop="content">
<el-input type="textarea" v-model="form.content"></el-input>
</el-form-item>
</el-form>
</template>
<script>
export default {
data() {
return {
form: {
name: '',
content: ''
},
rules: {
name: [{ required: true, message: '请输入业务名称', trigger: 'blur' }],
content: [{ required: true, message: '请输入审核内容', trigger: 'blur' }]
}
}
}
}
</script>
提交逻辑处理
通过 Axios 发送 HTTP 请求到后端接口,处理成功/失败状态。建议使用 async/await 处理异步操作:

methods: {
async submitForm() {
try {
await this.$refs.submitForm.validate()
const res = await this.$axios.post('/api/audit/submit', this.form)
if (res.data.code === 200) {
this.$message.success('提交成功')
this.$router.push('/audit/list')
}
} catch (error) {
this.$message.error(error.response?.data?.message || '提交失败')
}
}
}
状态管理优化
对于复杂业务场景,建议使用 Vuex 管理审核状态:

// store/modules/audit.js
const actions = {
async submitAudit({ commit }, payload) {
const res = await api.submitAudit(payload)
commit('SET_AUDIT_ID', res.data.id)
}
}
文件上传集成
如需上传附件,可集成上传组件:
<el-upload
action="/api/upload"
:on-success="handleUploadSuccess"
:file-list="fileList">
<el-button type="primary">点击上传</el-button>
</el-upload>
methods: {
handleUploadSuccess(response) {
this.form.attachments = response.data.path
}
}
加载状态优化
添加 loading 状态提升用户体验:
data() {
return {
loading: false
}
},
methods: {
async submitForm() {
this.loading = true
try {
//...提交逻辑
} finally {
this.loading = false
}
}
}






