File tree Expand file tree Collapse file tree 2 files changed +108
-1080
lines changed
Expand file tree Collapse file tree 2 files changed +108
-1080
lines changed Original file line number Diff line number Diff line change 33 <el-card class =" preview-card" >
44 <div slot =" header" >
55 <span >动态表单示例</span >
6- <el-button style =" float : right ; padding : 3px 0 " type =" text" >操作按钮</el-button >
6+ <div class =" pull-right" >
7+ <a target =" _blank" href =" https://codetrial.github.io" >@Codetrial</a >
8+ </div >
79 </div >
810 <el-row :gutter =" 24" >
911 <el-col :span =" 8" >
10- <el-form-builder :config =" config" :model =" formValues" label-width =" 48px" ></el-form-builder >
12+ <el-form-builder :config =" formConfig" :model =" formValues" label-width =" 80px" >
13+ <el-button >提交</el-button >
14+ </el-form-builder >
1115 </el-col >
12- <el-col :span =" 16" >
13- <el-input type =" textarea" ></el-input >
16+ <el-col :span =" 8" >
17+ <el-input v-model =" config.elements" type =" textarea" rows =" 24" ></el-input >
18+ </el-col >
19+ <el-col :span =" 8" >
20+ <el-input v-model =" config.rules" type =" textarea" rows =" 24" ></el-input >
1421 </el-col >
1522 </el-row >
1623 </el-card >
2128export default {
2229 name: ' FormBuilderPreview' ,
2330
31+ watch: {
32+ config: {
33+ deep: true ,
34+ immediate: true ,
35+ handler ({ rules, elements }) {
36+ try {
37+ this .formConfig = {
38+ rules: JSON .parse (rules),
39+ elements: JSON .parse (elements)
40+ }
41+ } catch (err) {
42+ console .error (' [JSON Parse Error] -> ' , err .message )
43+ }
44+ }
45+ }
46+ },
47+
2448 data () {
2549 return {
26- config: {
50+ formValues: {
51+ title: ' '
52+ },
53+
54+ formConfig: {
2755 rules: {},
28- elements: [
29- {
30- tag: ' el-input' ,
31- item: {
32- label: ' 标题'
33- },
34- detail: {
35- name: ' title'
36- }
37- }
38- ]
56+ elements: []
3957 },
4058
41- formValues: {
42- title: ' '
59+ config: {
60+ rules: JSON .stringify (
61+ {
62+ title: [
63+ { required: true , message: ' 请输入名称' },
64+ { max: 5 , message: ' 最多 5 个字符' }
65+ ]
66+ },
67+ null ,
68+ 4
69+ ),
70+
71+ elements: JSON .stringify (
72+ [
73+ {
74+ tag: ' el-input' ,
75+ item: {
76+ label: ' 标题'
77+ },
78+ detail: {
79+ name: ' title'
80+ }
81+ }
82+ ],
83+ null ,
84+ 4
85+ )
4386 }
4487 }
4588 }
@@ -51,4 +94,8 @@ export default {
5194 height : 100% ;
5295 margin : 48px ;
5396}
97+
98+ .pull-right {
99+ float : right ;
100+ }
54101 </style >
You can’t perform that action at this time.
0 commit comments