blog-web/code/list/save.vue
2024-05-09 14:47:05 +08:00

73 lines
1.7 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!--
* @Descripttion: 此文件由SCUI生成典型的VUE增删改列表页面组件
* @version: 1.0
* @Author: SCUI AutoCode 模板版本 1.0.0-beta.1
* @Date: <%= createDate %>
* @LastEditors: (最后更新作者)
* @LastEditTime: (最后更新时间)
-->
<template>
<el-form :model="form" :rules="rules" :disabled="mode=='show'" ref="dialogForm" label-width="100px" label-position="left">
<% column.forEach(function(item, index){ %>
<el-form-item label="<%= item.label %>" prop="<%= item.prop %>">
<el-input v-model="form.<%= item.prop %>" clearable></el-input>
</el-form-item>
<% })%>
</el-form>
</template>
<script>
export default {
props: {
mode: { type: String, default: "add" }
},
data() {
return {
//表单数据
form: {
<%= base.rowKey %>:"",
<% column.forEach(function(item, index){ %>
<%= item.prop %>: "",
<% })%>
},
//验证规则
rules: {
<% column.forEach(function(item, index){ %>
<%= item.prop %>: [
{required: true, message: '请输入<%= item.label %>'}
],
<% })%>
},
}
},
mounted(){
},
methods: {
//表单提交方法
submit(callback){
this.$refs.dialogForm.validate((valid) => {
if (valid) {
callback(this.form)
}else{
return false;
}
})
},
//表单注入数据
setData(data){
this.form.<%= base.rowKey %> = data.<%= base.rowKey %>
<% column.forEach(function(item, index){ %>
this.form.<%= item.prop %> = data.<%= item.prop %>
<% })%>
//可以和上面一样单个注入,也可以像下面一样直接合并进去
//Object.assign(this.form, data)
}
}
}
</script>
<style>
</style>