{"id":52617,"date":"2024-12-03T08:16:25","date_gmt":"2024-12-03T00:16:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52617\/"},"modified":"2024-12-03T08:16:25","modified_gmt":"2024-12-03T00:16:25","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-vue-js-%e4%b8%ad%e4%bd%bf%e7%94%a8%e7%bb%84%e4%bb%b6%e5%92%8c%e9%80%89%e9%a1%b9%e5%8d%a1%e7%bb%84%e4%bb%b6%e6%9d%a5%e5%8a%a8%e6%80%81%e6%98%be%e7%a4%ba%e5%a4%9a%e4%b8%aa-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52617\/","title":{"rendered":"\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f <\/h1>\n<p>\u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300a\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f \u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/1732237424673fd87013238.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f<\/p>\n<p>\u4e3a\u4e86\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528\u9009\u9879\u5361\u4e4b\u7c7b\u7684\u7ec4\u4ef6\uff0c\u5e76\u914d\u5408 Vue.js \u7684 component \u6807\u7b7e\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u6548\u679c\uff1a<\/p>\n<p>\u5728 app.vue \u4e2d\uff1a<\/p>\n<pre>&lt;template&gt;\n  &lt;div&gt;\n    &lt;h1&gt;\u6d4b\u8bd5&lt;\/h1&gt;\n    &lt;div&gt;\n      &lt;el-radio-group v-model=\"radio1\" @input=\"radio_onchange\"&gt;\n        &lt;el-radio-button v-for=\"(item, index) in page_list\" :key=\"index\" :label=\"item.view_code\"&gt;{{item.label}}&lt;\/el-radio-button&gt;\n      &lt;\/el-radio-group&gt;\n    &lt;\/div&gt;\n    &lt;div&gt;\n      &lt;keep-alive&gt;\n        &lt;component :is=\"radio1\" :message=\"message\"&gt;&lt;\/component&gt;\n      &lt;\/keep-alive&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nimport Vue from \"vue\";\nimport Test1 from \"@\/testComponent\/test1.vue\";\nimport Test3 from \"@\/testComponent\/test3.vue\";\n\nexport default {\n  data() {\n    return {\n      radio1: \"a1\",\n      message: undefined,\n      page_list: [\n        { seq: 1, view_code: \"a1\", label: \"\u6d4b\u8bd51\", type: 1 },\n        { seq: 3, view_code: \"b0\", label: \"\u7279\u5b9a\u6d4b\u8bd5\u7ec4\u4ef6A\", type: 2, message: \"\u53c2\u6570777\", is_regist: false },\n        { seq: 4, view_code: \"bc\", label: \"\u7279\u5b9a\u6d4b\u8bd5\u7ec4\u4ef6B\", type: 2, message: \"\u53c2\u6570666\", is_regist: false },\n      ],\n    };\n  },\n  components: {\n    a1: Test1,\n  },\n  methods: {\n    radio_onchange(value) {\n      const item = this.page_list.find((item) =&gt; item.view_code === value);\n      if (item.type != 2) {\n        return;\n      }\n      if (!item.is_regist) {\n        Vue.component(item.view_code, Test3);\n        item.is_regist = true;\n      }\n      this.message = item.message;\n    },\n  },\n};\n&lt;\/script&gt;<\/pre>\n<p>\u5728\u5305\u88f9\u4f60\u7684\u7ec4\u4ef6\u5b9e\u4f8b\u7684 &amp;lt;component&amp;gt; \u5143\u7d20\u5916\u5957\u4e00\u5c42 &amp;lt;keep-alive&amp;gt; \u6807\u7b7e\uff0c\u4e14\u6dfb\u52a0\u4e00\u4e2a\u552f\u4e00\u7684 key\u3002\u8fd9\u6837\uff0c\u6bcf\u4e2a\u7ec4\u4ef6\u5b9e\u4f8b\u90fd\u4f1a\u88ab\u89c6\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684\u7ec4\u4ef6\uff0c\u5e76\u4e14\u5728\u9009\u9879\u5361\u4e4b\u95f4\u5207\u6362\u65f6\u4e0d\u4f1a\u88ab\u9500\u6bc1\u548c\u91cd\u65b0\u521b\u5efa\u3002<\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u5b9e\u73b0\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff0c\u5e76\u4e14\u6bcf\u4e2a\u5b9e\u4f8b\u90fd\u53ef\u4ee5\u6709\u81ea\u5df1\u7684\u72b6\u6001\u548c\u5c5e\u6027\uff0c\u4ece\u800c\u6ee1\u8db3\u4f60\u7684\u8981\u6c42\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300a\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f \u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u7535\u8111\u600e\u4e48\u6279\u91cf\u5220\u9664qq\u597d\u53cb\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f \u77e5\u8bc6\u70b9\u638c\u63e1\u4e86\uff0c\u8fd8\u9700\u8981\u4e0d\u65ad\u7ec3\u4e60\u624d\u80fd\u719f\u7ec3\u8fd0\u7528\u3002\u4e0b\u9762\u7c73\u4e91\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u5b9e\u6218\uff0c\u624b\u628a\u624b\u6559\u5927\u5bb6\u5b66\u4e60\u300a\u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f \u300b\uff0c\u5728\u5b9e\u73b0\u529f\u80fd\u7684\u8fc7\u7a0b\u4e2d\u4e5f\u5e26\u5927\u5bb6\u91cd\u65b0\u6e29\u4e60\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6e29\u6545\u800c\u77e5\u65b0\uff0c\u56de\u5934\u770b\u770b\u8bf4\u4e0d\u5b9a\u53c8\u6709\u4e0d\u4e00\u6837\u7684\u611f\u609f\uff01 \u5982\u4f55\u5728 Vue.js \u4e2d\u4f7f\u7528\u7ec4\u4ef6\u548c\u9009\u9879\u5361\u7ec4\u4ef6\u6765\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff1f \u4e3a\u4e86\u52a8\u6001\u663e\u793a\u591a\u4e2a\u540c\u4e00\u7ec4\u4ef6\u5b9e\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528\u9009\u9879\u5361\u4e4b\u7c7b\u7684\u7ec4\u4ef6\uff0c\u5e76\u914d\u5408 Vue.js \u7684 component \u6807\u7b7e\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u5b9e\u73b0\u8fd9\u4e00\u6548\u679c\uff1a \u5728 app.vue \u4e2d\uff1a &lt;template&gt; &lt;div&gt; &lt;h1&gt;\u6d4b\u8bd5&lt;\/h1&gt; &lt;div&gt; &lt;el-radio-group v-model=&#8221;radio1&#8243; @input=&#8221;radio_onchange&#8221;&gt; &lt;el-radio-button v-for=&#8221;(item, index) in page_list&#8221; :key=&#8221;index&#8221; :label=&#8221;item.view_code&#8221;&gt;{{item.label}}&lt;\/el-radio-button&gt; &lt;\/el-radio-group&gt; &lt;\/div&gt; &lt;div&gt; &lt;keep-alive&gt; &lt;component :is=&#8221;radio1&#8243; :message=&#8221;message&#8221;&gt;&lt;\/component&gt; &lt;\/keep-alive&gt; &lt;\/div&gt; &lt;\/div&gt; &lt;\/template&gt; &lt;script&gt; import Vue from &#8220;vue&#8221;; import Test1 from &#8220;@\/testComponent\/test1.vue&#8221;; import Test3 from [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52617","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52617"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52617\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}