{"id":244062,"date":"2022-06-05T10:29:22","date_gmt":"2022-06-05T02:29:22","guid":{"rendered":"https:\/\/gulass.cn\/?p=244062"},"modified":"2022-05-31T20:31:44","modified_gmt":"2022-05-31T12:31:44","slug":"for-form-linux","status":"publish","type":"post","link":"https:\/\/gulass.cn\/for-form-linux.html","title":{"rendered":"\u7b80\u5355\u4ecb\u7ecdv-for\u4e2d\u52a8\u6001\u6821\u9a8cel-form\u8868\u5355\u9879\u7684\u5b9e\u8df5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u8868\u5355\u4fdd\u5b58\u7684\u529f\u80fd\uff0c\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86v-for\u4e2d\u52a8\u6001\u6821\u9a8cel-form\u8868\u5355\u9879\u7684\u5b9e\u8df5\uff0c\u6587\u4e2d\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u8005\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u5b66\u4e60\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u4eec\u4e0b\u9762\u968f\u7740\u5c0f\u7f16\u6765\u4e00\u8d77\u5b66\u4e60\u5b66\u4e60\u5427
<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u95ee\u9898\u63cf\u8ff0<\/strong><\/div>\n

\u5728\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u8868\u5355\u4fdd\u5b58\u7684\u529f\u80fd\uff0c\u5728\u8868\u5355\u4fdd\u5b58\u524d\uff0c\u5e38\u5e38\u9700\u8981\u505a\u8868\u5355\u5fc5\u586b\u9879\u7684\u6821\u9a8c\uff0c\u6821\u9a8c\u901a\u8fc7\u4ee5\u540e\u624d\u53bb\u53d1\u8bf7\u6c42\u4fdd\u5b58\u8868\u5355\u6570\u636e\u3002<\/p>\n

\u4f46\u662f\uff0c\u8fd9\u4e2a\u8868\u5355\u5982\u679c\u662f\u52a8\u6001\u7684\uff0c\u5373\uff1a\u53ef\u4ee5\u65b0\u589e\u76f8\u540c\u7684\u8868\u5355\u3002\u6bd4\u5982\u8fd9\u4e2a\u8868\u5355\u6709\u8f93\u5165\u6846\u548c\u4e0b\u62c9\u6846\u9700\u8981\u6821\u9a8c\uff0c\u70b9\u51fb\u6dfb\u52a0\u8868\u683c\u6309\u94ae\uff0c\u518d\u65b0\u589e\u4e00\u4e2a\u76f8\u540c\u7684\u8868\u5355\uff0c\u540c\u6837\u65b0\u7684\u8fd9\u4e2a\u8868\u5355\u5bf9\u5e94\u7684\u8f93\u5165\u6846\u548c\u4e0b\u62c9\u6846\u4e5f\u9700\u8981\u6821\u9a8c\u3002<\/p>\n

\u672c\u6587\u8bb0\u5f55\u4e00\u4e0b\u5bf9\u5e94\u4ee3\u7801\u5199\u6cd5\u601d\u8def\uff0c\u6211\u4eec\u5148\u770b\u4e00\u4e0b\u6548\u679c\u56fe\uff1a<\/p>\n

\u6548\u679c\u56fe<\/strong><\/div>\n

\"\"<\/p>\n

\u4ee3\u7801\u601d\u8def<\/strong><\/div>\n

\u8868\u5355\u7684\u4e3b\u6570\u636e\u662f\u8981\u5199\u6210\u5bf9\u8c61\u5f62\u5f0f :model=\"ruleForm\" \u4e0d\u8fc7\u65e2\u7136\u662f\u8981\u52a8\u6001\u7684\uff0c\u80af\u5b9a\u662f\u8981\u5faa\u73af\u5462\uff0c\u6240\u4ee5\uff0c\u53ef\u4ee5\u5199\u6210\u8fd9\u6837\uff1a<\/p>\n

ruleForm: {\r\n        \/\/ \u52a8\u6001\u5faa\u73af\u9879\u6570\u7ec4\r\n        formItemArr: [\r\n          {\r\n            name: \"\",\r\n            gender: \"\",\r\n          },\r\n        ],\r\n      },<\/pre>\n

\u70b9\u51fb\u6dfb\u52a0\u8868\u683c\u7684\u65f6\u5019\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5push\u5bf9\u5e94\u9879\u5c31\u884c\u5566\uff0c\u5373\uff0c\u8fd9\u6837\uff1a<\/p>\n

\/\/ \u6dfb\u52a0\u4e00\u4e2a\u8868\u683c\r\n    addForm () {\r\n      let itemObj = {\r\n        name: \"\",\r\n        gender: \"\",\r\n      };\r\n      this .ruleForm.formItemArr.push(itemObj);\r\n    },<\/pre>\n

\u91cd\u70b9\u6765\u55bd\uff0c\u56e0\u4e3a\u662f\u5faa\u73af\u7684\uff0c\u6240\u4ee5prop\u4e5f\u8981\u53d8\u6210\u52a8\u6001\u7684\u4e86\uff0c\u8981\u62fc\u63a5\u4e0aindex\uff0c\u5c31\u53d8\u6210\u6839\u636e\u7d22\u5f15\u53bb\u627e\u5bf9\u5e94\u7684\u6821\u9a8c\u9879\u4e86\uff0c\u5373\u4e3a\uff1a:prop=\"'formItemArr.' + index + '.name'\" \uff0c\u8fd9\u6837\u7684\u8bdd\uff0c\u5c31\u53d8\u6210\u4e86\uff1aprop=\"formItemArr.0.name\"\u3001prop=\"formItemArr.1.name\"\u3001prop=\"formItemArr.2.name\" ... \u8fd9\u6837\u7684\u8bdd\uff0c\u5c31\u53ef\u4ee5\u7167\u987e\u5230\u6bcf\u4e00\u9879\u4e2d\u7684\u6bcf\u4e00\u4e2a\u7ed1\u5b9a\u7684\u503c\u4e86\uff0c\u6821\u9a8c\u5c31\u4e0d\u4f1a\u6f0f\u6389<\/p>\n

\u6821\u9a8c\u89c4\u5219\u5199\u6210\u5185\u8054\u5c31\u53ef\u4ee5\u89e6\u53d1\u6821\u9a8c\u51fd\u6570this.$refs[\"ruleForm\"].validate((val) => {})\u4e86<\/p>\n

< el-form-item\r\n          label=\"\u59d3\u540d\"\r\n          :prop=\"'formItemArr.' + index + '.name'\"\r\n          :rules=\"{\r\n            required: true,\r\n            message: '\u8bf7\u586b\u5199',\r\n            trigger: 'blur',\r\n          }\"\r\n        >\r\n        ......<\/pre>\n
\u5b8c\u6574\u4ee3\u7801<\/strong><\/div>\n

\u6f14\u793a\u7684\u8bdd\uff0c\u5927\u5bb6\u76f4\u63a5\u590d\u5236\u7c98\u8d34\u5373\u53ef<\/p>\n

< template>\r\n  < div class=\"box\">\r\n    < el-button @click=\"addForm\" size=\"mini\" type=\"primary\" plain\r\n      >\u6dfb\u52a0\u8868\u683c< \/el-button\r\n    >\r\n    < el-button @click=\"saveForm\" size=\"mini\" type=\"primary\" plain\r\n      >\u4fdd\u5b58\u8868\u683c< \/el-button\r\n    >\r\n    < br \/>\r\n    < br \/>\r\n    < el-form\r\n      :model=\"ruleForm\"\r\n      ref=\"ruleForm\"\r\n      label-width=\"100px\"\r\n      class=\"formform\"\r\n    >\r\n      < div\r\n        class=\"formformItemClass\"\r\n        v-for=\"(item, index) in ruleForm.formItemArr\"\r\n        :key=\"index\"\r\n      >\r\n        < el-form-item\r\n          label=\"\u59d3\u540d\"\r\n          :prop=\"'formItemArr.' + index + '.name'\"\r\n          :rules=\"{\r\n            required: true,\r\n            message: '\u8bf7\u586b\u5199',\r\n            trigger: 'blur',\r\n          }\"\r\n        >\r\n          < el-input\r\n            size=\"mini\"\r\n            v-model.trim=\"item.name\"\r\n            placeholder=\"\u8bf7\u586b\u5199\"\r\n            style=\"width: 200px\"\r\n          >< \/el-input>\r\n        < \/el-form-item>\r\n        < el-form-item\r\n          label=\"\u6027\u522b\"\r\n          :prop=\"'formItemArr.' + index + '.gender'\"\r\n          :rules=\"{\r\n            required: true,\r\n            message: '\u8bf7\u9009\u62e9',\r\n            trigger: 'change',\r\n          }\"\r\n        >\r\n          < el-select\r\n            clearable\r\n            size=\"mini\"\r\n            v-mo del=\"item.gender\"\r\n            place holder=\"\u8bf7\u9009\u62e9\"\r\n          >\r\n            < el-option label=\"\u7537\" value=\"\u7537\">< \/el-option>\r\n            < el-option label=\"\u5973\" value=\"\u5973\">< \/el-option>\r\n          < \/el-select>\r\n        < \/el-form-item>\r\n      < \/div>\r\n    < \/el-form>\r\n  < \/div>\r\n< \/template>\r\n \r\n< script>\r\nexport default {\r\n  data() {\r\n    return {\r\n      ruleForm: {\r\n        \/\/ \u52a8\u6001\u5faa\u73af\u9879\u6570\u7ec4\r\n        formItemArr: [\r\n          {\r\n            name: \"\",\r\n            gender: \"\",\r\n          },\r\n        ],\r\n      },\r\n    };\r\n  },\r\n  met hods: {\r\n    \/\/ \u6dfb\u52a0\u4e00\u4e2a\u8868\u683c\r\n    add Form() {\r\n      let ite mObj = {\r\n        name: \"\",\r\n        gender: \"\",\r\n      };\r\n      this.rule Form.form Item Arr.push(itemObj);\r\n    },\r\n    \/\/ \u4fdd\u5b58\u8868\u683c\r\n    save Form() {\r\n      this .$refs[\"ruleForm\"].validate((val) => {\r\n        if (val) {\r\n          con sole.log(\"\u7b26\u5408\u8981\u6c42\uff0c\u4fdd\u5b58\u6210\u529f\", this.ruleForm);\r\n        } else {\r\n          cons ole.log(\"error submit!!\");\r\n          re turn false;\r\n        }\r\n      });\r\n    },\r\n  },\r\n};\r\n< \/script>\r\n \r\n< style lang=\"less\" scoped>\r\n. box {\r\n  wi dth: 100%;\r\n  hei ght: 100%;\r\n  box -sizing: border-box;\r\n  pad ding: 24px;\r\n  .for mform {\r\n    wi dth: 360px;\r\n    .for mformItemClass {\r\n      pa dding-top: 24px;\r\n      bo rder: 2px dashed #ccc;\r\n      ma rgin-bottom: 18px;\r\n    }\r\n  }\r\n}\r\n< \/style><\/pre>\n

\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8ev-for\u4e2d\u52a8\u6001\u6821\u9a8cel-form\u8868\u5355\u9879\u7684\u5b9e\u8df5\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u6211\u4eec\u7ecf\u5e38\u4f1a\u9047\u5230\u8868\u5355\u4fdd\u5b58\u7684\u529f\u80fd\uff0c\u5728\u8868\u5355\u4fdd\u5b58\u524d\uff0c\u5e38\u5e38\u9700\u8981\u505a\u8868\u5355\u5fc5\u586b\u9879\u7684\u6821\u9a8c\uff0c\u6821\u9a8c\u901a\u8fc7\u4ee5\u540e\u624d\u53bb\u53d1\u8bf7\u6c42\u4fdd […]<\/p>\n","protected":false},"author":1479,"featured_media":132848,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-244062","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/244062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=244062"}],"version-history":[{"count":7,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/244062\/revisions"}],"predecessor-version":[{"id":244071,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/244062\/revisions\/244071"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/132848"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=244062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=244062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=244062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}