{"id":1010,"date":"2023-03-12T09:02:32","date_gmt":"2023-03-12T01:02:32","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1010"},"modified":"2023-04-29T13:16:49","modified_gmt":"2023-04-29T05:16:49","slug":"several-ways-for-vue-to-register-components","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/several-ways-for-vue-to-register-components\/","title":{"rendered":"Vue\u6ce8\u518c\u7ec4\u4ef6\u7684\u51e0\u79cd\u65b9\u5f0f"},"content":{"rendered":"<h2>\u5168\u5c40\u6ce8\u518c<\/h2>\n<p>\u8be5\u65b9\u5f0f\u6ce8\u518c\u7ec4\u4ef6\u5fc5\u987b\u5728vue\u5b9e\u4f8b\u5316\u4e4b\u524d\u58f0\u660e<\/p>\n<pre><code class=\"language-javascript\">Vue.component(&#039;tag-name&#039;, {})<\/code><\/pre>\n<p><!-- more --><\/p>\n<h2>\u5c40\u90e8\u6ce8\u518c<\/h2>\n<pre><code class=\"language-javascript\">var Child = {\n  template: &#039;&lt;div&gt;A custom component!&lt;\/div&gt;&#039;\n}\nnew Vue({\n  \/\/ ...\n  components: {\n    \/\/ &lt;my-component&gt; \u5c06\u53ea\u5728\u7236\u6a21\u677f\u53ef\u7528\n    &#039;my-component&#039;: Child\n  }\n})<\/code><\/pre>\n<h2>\u6269\u5c55\u5b9e\u4f8b<\/h2>\n<pre><code class=\"language-javascript\">\/\/ \u5b9a\u4e49\u4e00\u4e2a\u6df7\u5408\u5bf9\u8c61\nvar myMixin = {\n  created: function () {\n    this.hello()\n  },\n  methods: {\n    hello: function () {\n      console.log(&#039;hello from mixin!&#039;)\n    }\n  }\n}\n\/\/ \u5b9a\u4e49\u4e00\u4e2a\u4f7f\u7528\u6df7\u5408\u5bf9\u8c61\u7684\u7ec4\u4ef6\nvar Component = Vue.extend({\n  mixins: [myMixin]\n})\nvar component = new Component() \/\/ -&gt; &quot;hello from mixin!&quot;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5168\u5c40\u6ce8\u518c \u8be5\u65b9\u5f0f\u6ce8\u518c\u7ec4\u4ef6\u5fc5\u987b\u5728vue\u5b9e\u4f8b\u5316\u4e4b\u524d\u58f0\u660e Vue.component(&#039;tag-name&#038; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1010","post","type-post","status-publish","format-standard","hentry","category-vue"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1010"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1010\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}