{"id":1089,"date":"2022-11-13T16:24:00","date_gmt":"2022-11-13T08:24:00","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=1089"},"modified":"2022-10-18T16:42:06","modified_gmt":"2022-10-18T08:42:06","slug":"vue-component%e5%8a%a8%e6%80%81%e7%bb%84%e4%bb%b6%e5%bc%80%e5%8f%91","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=1089","title":{"rendered":"Vue-Component\u52a8\u6001\u7ec4\u4ef6\u5f00\u53d1"},"content":{"rendered":"\n<p>\u524d\u6bb5\u65f6\u95f4\u9047\u5230\u4e00\u4e2a\u9700\u6c42\uff0c\u4e00\u4e2a\u5217\u8868 \u4f1a\u5b58\u5728\u5f88\u591a\u79cd\u4e0d\u540c\u7684\u6837\u5f0f\u4e0e\u6570\u636e\u5185\u5bb9\uff0c\u5982\u679c\u7528v-if\u4f9d\u6b21\u5224\u65ad\uff0c\u4e5f\u80fd\u5b9e\u73b0\uff0c\u4f46\u662f\u6bd4\u8f83low\uff0c<\/p>\n\n\n\n<p>\u4f1a\u9020\u6210\u4ee3\u7801\u5197\u4f59\uff0c\u6240\u4ee5\u901a\u8fc7\u540c\u4e8b\u7684\u70b9\u64ad \uff0c\u81ea\u5df1\u67e5\u4e86\u4e0b\u8d44\u6599\uff0c<\/p>\n\n\n\n<p>\u6587\u6863\u5730\u5740\uff1ahttps:\/\/www.javascriptc.com\/vue3js\/api\/application-api.html#component<\/p>\n\n\n\n<p>\u5b9e\u9645\u4e0a\u6211\u505a\u597d\u7684\u6700\u7ec8\u6548\u679c\u662f\u8fd9\u6837 \uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" src=\"http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2022\/10\/image-5.png\" alt=\"\" class=\"wp-image-1090\" width=\"267\" height=\"350\" srcset=\"http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2022\/10\/image-5.png 757w, http:\/\/blog.xrhoujie.com\/wp-content\/uploads\/2022\/10\/image-5-229x300.png 229w\" sizes=\"(max-width: 267px) 100vw, 267px\" \/><\/figure>\n\n\n\n<p>\u4f7f\u7528component \u7684:is=&#8221;xxx&#8221;\u6765\u7d22\u5f15\u5bf9\u5e94\u7ec4\u4ef6\uff0c\u5e76\u4e14\u5c55\u793a\uff0c\u76f4\u63a5\u4e0a\u4ee3\u7801\u5427 \uff1a<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;div v-for=\"(n, i) in item\" :key=\"i\">\n    &lt;component\n            :is=\"stateComponent&#91;n.view_type]\" \n            :listData=\"n\"\n            :personData=\"personData\"\n   >&lt;\/component>\n&lt;\/div>\n\nexport default {\n  components: {\n    ArchivesTask: defineAsyncComponent(() =>\n      import(\"..\/archives\/archivesTask.vue\") \/\/\u7ec4\u4ef61\n    ),\n    ArchivesReport: defineAsyncComponent(() =>\n      import(\"@\/views\/archives\/archivesReport\")<meta charset=\"utf-8\">\/\/\u7ec4\u4ef62\n    ),\n    ArchivesWeekly: defineAsyncComponent(() =>\n      import(\"@\/views\/archives\/archivesWeekly\")<meta charset=\"utf-8\">\/\/\u7ec4\u4ef63\n    ),\n    ArchivesMonthly: defineAsyncComponent(() =>\n      import(\"@\/views\/archives\/archivesMonthly\")<meta charset=\"utf-8\">\/\/\u7ec4\u4ef64\n    ),\n    ArchivesPlan: defineAsyncComponent(() =>\n      import(\"@\/views\/archives\/archivesPlan\")<meta charset=\"utf-8\">\/\/\u7ec4\u4ef65\n    ),\n    ArchivesAssess: defineAsyncComponent(() =>\n      import(\"@\/views\/archives\/archivesAssess\")<meta charset=\"utf-8\">\/\/\u7ec4\u4ef66\n    ),\n    ArchivesCollect: defineAsyncComponent(() =>\n      import(\"@\/views\/archives\/archivesCollect\")<meta charset=\"utf-8\">\/\/\u7ec4\u4ef67\n    ),\n  },\n\ndata() {\n    return {\n      stateComponent: {\n        \u8bad\u7ec3\u4efb\u52a1: \"ArchivesTask\",\n        \u8bad\u7ec3\u62a5\u544a_\u9636\u6bb5: \"ArchivesReport\",\n        \u8bad\u7ec3\u62a5\u544a_\u5468\u62a5: \"ArchivesWeekly\",\n        \u8bad\u7ec3\u62a5\u544a_\u6708\u62a5: \"archivesMonthly\",\n        \u8bad\u7ec3\u65b9\u6848: \"ArchivesPlan\",\n        \u9636\u6bb5\u8bc4\u4f30: \"ArchivesAssess\",\n        \u75c5\u5386: \"ArchivesCollect\",\n      },\n      listData: {},\n      tabsTitle:&#91;'\u5168\u90e8','\u75c5\u5386', '\u9636\u6bb5\u8bc4\u4f30','\u8bad\u7ec3\u65b9\u6848','\u8bad\u7ec3\u4efb\u52a1','\u8bad\u7ec3\u62a5\u544a'],\n<meta charset=\"utf-8\">      item:&#91;],\n    };\n  },\n\n\u7b80\u5355\u8bf4\u4e0b\uff0c\u6838\u5fc3\u4ee3\u7801\u5728\u8fd9\u4e2a \n\n&lt;component <meta charset=\"utf-8\">:is=\"stateComponent&#91;n.view_type]\"> \n \n\/\/\u83b7\u53d6n.view_type\u7684value  \u7d22\u5f15\u6620\u5c04\u5728stateComponent\u5185\u90e8\u7684key\u503c\uff0c\u83b7\u53d6value\u7ec4\u4ef6\uff0c\u5e76\u5c55\u793a,\n<meta charset=\"utf-8\">:listData=\"n\" \u662f\u5f53\u524d\u884c\u7684 \u6570\u636e\u4fe1\u606f\uff0c\u901a\u5e38\u662f\u8981\u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\u7684\u3002\n\n\u628a\u5217\u8868\u7684\u6bcf\u4e00\u4e0d\u540c\u7c7b\u9879\u90fd\u62c6\u5206\u6210\u7ec4\u4ef6\uff0c\u901a\u8fc7component\u6765\u7ec4\u5408 \u8fbe\u5230\u6a21\u5757\u5316\u7684\u6536\u76ca\uff0c\n\n<\/code><\/pre>\n\n\n\n<p>\u5c31\u662f\u8fd9\u6837\u5b50\u4e86 \uff0c\u5728\u5de5\u4f5c\u7684\u8fc7\u7a0b\u4e2d\u80fd\u4e0d\u65ad\u5b66\u4e60 \u5b8c\u5584\u81ea\u5df1 \u662f\u4e00\u4ef6\u8ba9\u4eba\u5f00\u5fc3\u7684\u4e8b\u513f \u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u6bb5\u65f6\u95f4\u9047\u5230\u4e00\u4e2a\u9700\u6c42\uff0c\u4e00\u4e2a\u5217\u8868 \u4f1a\u5b58\u5728\u5f88\u591a\u79cd\u4e0d\u540c\u7684\u6837\u5f0f\u4e0e\u6570\u636e\u5185\u5bb9\uff0c\u5982\u679c\u7528v-if\u4f9d\u6b21\u5224\u65ad\uff0c\u4e5f\u80fd\u5b9e\u73b0\uff0c\u4f46\u662f\u6bd4\u8f83l [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[41],"tags":[38],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/1089"}],"collection":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1089"}],"version-history":[{"count":1,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/1089\/revisions"}],"predecessor-version":[{"id":1091,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/1089\/revisions\/1091"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1089"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}