{"id":3340,"date":"2024-11-10T08:26:04","date_gmt":"2024-11-10T00:26:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3340\/"},"modified":"2024-11-10T08:26:04","modified_gmt":"2024-11-10T00:26:04","slug":"vue%e5%bc%95%e5%85%a5js%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3340\/","title":{"rendered":"vue\u5f15\u5165js\u5982\u4f55\u4f7f\u7528"},"content":{"rendered":"<blockquote><p>\n  \u5728 vue.js \u4e2d\u5f15\u5165\u548c\u4f7f\u7528 javascript \u6709\u4e24\u79cd\u65b9\u5f0f\uff1a\u5168\u5c40\u5f15\u5165\uff08\u901a\u8fc7 vue.component() \u6ce8\u518c\u7ec4\u4ef6\uff09\u548c\u5c40\u90e8\u5f15\u5165\uff08\u5728\u7ec4\u4ef6\u6587\u4ef6\u4e2d\u4f7f\u7528 import \u8bed\u53e5\uff09\u3002\u5168\u5c40\u5bfc\u5165\u5728\u6240\u6709\u7ec4\u4ef6\u4e2d\u53ef\u7528\uff0c\u800c\u5c40\u90e8\u5bfc\u5165\u4ec5\u5728\u8be5\u7ec4\u4ef6\u5185\u53ef\u7528\u3002\u5bfc\u5165\u7684 javascript \u6a21\u5757\u53ef\u7528\u4e8e\u7ec4\u4ef6\u6a21\u677f\u548c\u811a\u672c\u4e2d\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110810034287690.jpg\" class=\"aligncenter\" title=\"vue\u5f15\u5165js\u5982\u4f55\u4f7f\u7528\u63d2\u56fe\" alt=\"vue\u5f15\u5165js\u5982\u4f55\u4f7f\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>Vue.js \u4e2d\u5f15\u5165\u548c\u4f7f\u7528 JavaScript<\/strong><\/p>\n<p>\u5728 Vue.js \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u6765\u5f15\u5165\u548c\u4f7f\u7528 JavaScript\uff1a<\/p>\n<p><strong>1. \u5168\u5c40\u5f15\u5165<\/strong><\/p>\n<ul>\n<li>\u5728 mn.js \u6587\u4ef6\u4e2d\u4f7f\u7528 Vue.component() \u6ce8\u518c\u5168\u5c40\u7ec4\u4ef6\u3002<\/li>\n<li>\u5728\u7ec4\u4ef6\u6a21\u677f\u4e2d\u4f7f\u7528 \u6807\u7b7e\u5f15\u7528\u6ce8\u518c\u7684\u7ec4\u4ef6\u3002 <\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ main.js\nVue.component('my-component', {\n  template: '&lt;div&gt;\u5168\u5c40\u7ec4\u4ef6&lt;\/div&gt;'\n});\n\n\/\/ App.vue\n&lt;template&gt;\n  &lt;my-component&gt;&lt;\/my-component&gt;\n&lt;\/template&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5c40\u90e8\u5f15\u5165<\/strong><\/p>\n<ul>\n<li>\u5728\u7ec4\u4ef6\u6587\u4ef6\u4e2d\u4f7f\u7528 import \u8bed\u53e5\u5bfc\u5165 JavaScript \u6a21\u5757\u6216\u7b2c\u4e09\u65b9\u5e93\u3002<\/li>\n<li>\u5728\u7ec4\u4ef6\u6a21\u677f\u6216\u811a\u672c\u4e2d\u4f7f\u7528\u5bfc\u5165\u7684\u6a21\u5757\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ MyComponent.vue\n&lt;script&gt;\nimport moment from 'moment';\n&lt;\/script&gt;\n\n&lt;template&gt;\n  &lt;div&gt;\n    {{ moment().format('YYYY-MM-DD') }}\n  &lt;\/div&gt;\n&lt;\/template&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u5bfc\u5165\u7684 JavaScript \u6a21\u5757<\/strong><\/p>\n<p>\u4e00\u65e6\u5bfc\u5165 JavaScript \u6a21\u5757\uff0c\u5c31\u53ef\u4ee5\u50cf\u8fd9\u6837\u4f7f\u7528\u5b83\u4eec\uff1a<\/p>\n<pre>\/\/ \u4f7f\u7528 moment.js \u683c\u5f0f\u5316\u65e5\u671f\nconst formattedDate = moment().format('YYYY-MM-DD');\n\n\/\/ \u4f7f\u7528 Axios \u53d1\u51fa HTTP \u8bf7\u6c42\nconst response = await axios.get('https:\/\/example.com\/api');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u5bfc\u5165\u7684 JavaScript \u6a21\u5757\u4e0e Vue.js \u517c\u5bb9\u3002<\/li>\n<li>\u5c40\u90e8\u5bfc\u5165\u53ea\u5728\u8be5\u7ec4\u4ef6\u4e2d\u53ef\u7528\uff0c\u800c\u5168\u5c40\u5bfc\u5165\u53ef\u5728\u6240\u6709\u7ec4\u4ef6\u4e2d\u4f7f\u7528\u3002<\/li>\n<li>\u5c3d\u91cf\u907f\u514d\u5168\u5c40\u5f15\u5165\uff0c\u56e0\u4e3a\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5f15\u5165js\u5982\u4f55\u4f7f\u7528\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 vue.js \u4e2d\u5f15\u5165\u548c\u4f7f\u7528 javascript \u6709\u4e24\u79cd\u65b9\u5f0f\uff1a\u5168\u5c40\u5f15\u5165\uff08\u901a\u8fc7 vue.component() \u6ce8\u518c\u7ec4\u4ef6\uff09\u548c\u5c40\u90e8\u5f15\u5165\uff08\u5728\u7ec4\u4ef6\u6587\u4ef6\u4e2d\u4f7f\u7528 import \u8bed\u53e5\uff09\u3002\u5168\u5c40\u5bfc\u5165\u5728\u6240\u6709\u7ec4\u4ef6\u4e2d\u53ef\u7528\uff0c\u800c\u5c40\u90e8\u5bfc\u5165\u4ec5\u5728\u8be5\u7ec4\u4ef6\u5185\u53ef\u7528\u3002\u5bfc\u5165\u7684 javascript \u6a21\u5757\u53ef\u7528\u4e8e\u7ec4\u4ef6\u6a21\u677f\u548c\u811a\u672c\u4e2d\u3002 Vue.js \u4e2d\u5f15\u5165\u548c\u4f7f\u7528 JavaScript \u5728 Vue.js \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\u6765\u5f15\u5165\u548c\u4f7f\u7528 JavaScript\uff1a 1. \u5168\u5c40\u5f15\u5165 \u5728 mn.js \u6587\u4ef6\u4e2d\u4f7f\u7528 Vue.component() \u6ce8\u518c\u5168\u5c40\u7ec4\u4ef6\u3002 \u5728\u7ec4\u4ef6\u6a21\u677f\u4e2d\u4f7f\u7528 \u6807\u7b7e\u5f15\u7528\u6ce8\u518c\u7684\u7ec4\u4ef6\u3002 \u793a\u4f8b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \/\/ main.js Vue.component(&#8216;my-component&#8217;, { template: &#8216;&lt;div&gt;\u5168\u5c40\u7ec4\u4ef6&lt;\/div&gt;&#8217; }); \/\/ App.vue &lt;template&gt; &lt;my-component&gt;&lt;\/my-component&gt; &lt;\/template&gt; \u767b\u5f55\u540e\u590d\u5236 2. \u5c40\u90e8\u5f15\u5165 \u5728\u7ec4\u4ef6\u6587\u4ef6\u4e2d\u4f7f\u7528 import \u8bed\u53e5\u5bfc\u5165 JavaScript \u6a21\u5757\u6216\u7b2c\u4e09\u65b9\u5e93\u3002 \u5728\u7ec4\u4ef6\u6a21\u677f\u6216\u811a\u672c\u4e2d\u4f7f\u7528\u5bfc\u5165\u7684\u6a21\u5757\u3002 \u793a\u4f8b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \/\/ MyComponent.vue &lt;script&gt; [&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-3340","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3340","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=3340"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3340\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}