{"id":27893,"date":"2024-11-24T12:44:56","date_gmt":"2024-11-24T04:44:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27893\/"},"modified":"2024-11-24T12:44:56","modified_gmt":"2024-11-24T04:44:56","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e9%81%ae%e7%bd%a9%e5%8a%a8%e7%94%bb%e5%ae%9e%e7%8e%b0-vue-3-%e4%b8%ad%e7%9a%84%e5%9b%be%e5%83%8f%e8%bd%ae%e6%92%ad%e6%95%88%e6%9e%9c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27893\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528\u906e\u7f69\u52a8\u753b\u5b9e\u73b0 Vue 3 \u4e2d\u7684\u56fe\u50cf\u8f6e\u64ad\u6548\u679c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173132952464629.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528\u906e\u7f69\u52a8\u753b\u5b9e\u73b0 Vue 3 \u4e2d\u7684\u56fe\u50cf\u8f6e\u64ad\u6548\u679c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528\u906e\u7f69\u52a8\u753b\u5b9e\u73b0 Vue 3 \u4e2d\u7684\u56fe\u50cf\u8f6e\u64ad\u6548\u679c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5b9e\u73b0\u56fe\u50cf\u8f6e\u64ad\u6548\u679c\u7684 3 \u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u4f60\u9047\u5230\u7684\u95ee\u9898\u662f\u6839\u636e\u63d0\u4f9b\u7684\u7f51\u7ad9\u793a\u4f8b\uff0c\u5728 Vue 3 \u4e2d\u5b9e\u73b0\u56fe\u50cf\u81ea\u52a8\u5207\u6362\u6548\u679c\u3002\u7f51\u7ad9\u4e0a\u7684\u6548\u679c\u662f\u901a\u8fc7\u4f7f\u7528\u4e24\u4e2a\u5e26\u6709\u201canimation\u201d\u7c7b\u7684\u76d2\u5b50\u6765\u5b9e\u73b0\u7684\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a\u906e\u7f69\u52a8\u753b<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u4f60\u7684\u95ee\u9898\uff0c\u4e00\u79cd\u53ef\u884c\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528\u906e\u7f69\u52a8\u753b\u3002\u906e\u7f69\u52a8\u753b\u662f\u4e00\u79cd\u901a\u8fc7\u5728\u5143\u7d20\u4e0a\u6dfb\u52a0\u8def\u5f84\u6765\u521b\u5efa\u6548\u679c\u7684\u6280\u672f\uff0c\u8be5\u8def\u5f84\u4f1a\u6cbf\u7740\u8be5\u8def\u5f84\u79fb\u52a8\u3002<\/p>\n<p><strong>\u5b9e\u73b0\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u5c06\u4e00\u4e2a\u906e\u7f69\u6dfb\u52a0\u5230\u6700\u4e0a\u5c42\u7684\u56fe\u50cf\u3002<\/li>\n<li>\u5728\u906e\u7f69\u4e0a\u8bbe\u7f6e\u8def\u5f84\u52a8\u753b\u3002<\/li>\n<li>\u5f53\u8def\u5f84\u52a8\u753b\u5b8c\u6210\u540e\uff0c\u5207\u6362\u6700\u4e0a\u5c42\u7684\u56fe\u50cf\u3002<\/li>\n<\/ol>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>&lt;div class=\"shop-card\"&gt;\n  &lt;div class=\"mask\"&gt;\n    &lt;svg&gt;\n      &lt;path d=\"M 0 0 L 100% 0 L 100% 100% L 0 100% Z\" \/&gt;\n    &lt;\/svg&gt;\n  &lt;\/div&gt;\n  @@##@@\n&lt;\/div&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>.mask {\n  position: absolute;\n  width: 100%;\n  height: 100%;\n  overflow: hidden;\n}\n\n.mask path {\n  stroke: black;\n  stroke-width: 1;\n  fill: none;\n}\n\n.mask path.active {\n  animation: path 5s linear infinite;\n}\n\n@keyframes path {\n  0% {\n    stroke-dashoffset: 0;\n  }\n  100% {\n    stroke-dashoffset: 100%;\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>\/\/ Vue 3 \u7ec4\u4ef6\u7684 JavaScript \u4ee3\u7801\nexport default {\n  mounted() {\n    const path = this.$refs.path;\n    path.addEventListener('transitionend', this.onPathEnd);\n  },\n  unmounted() {\n    const path = this.$refs.path;\n    path.removeEventListener('transitionend', this.onPathEnd);\n  },\n  methods: {\n    onPathEnd() {\n      \/\/ \u5728\u8def\u5f84\u52a8\u753b\u5b8c\u6210\u540e\u5207\u6362\u56fe\u50cf\n      \/\/ ...\n    }\n  }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n<p>\u4f7f\u7528\u906e\u7f69\u52a8\u753b\u53ef\u4ee5\u8ba9\u4f60\u5b9e\u73b0\u4e00\u4e2a\u52a8\u6001\u7684\u56fe\u50cf\u8f6e\u64ad\u6548\u679c\uff0c\u8fd9\u4e0e\u63d0\u4f9b\u7684\u7f51\u7ad9\u793a\u4f8b\u7c7b\u4f3c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u5177\u6709\u4e0d\u540c\u6570\u91cf\u56fe\u50cf\u7684\u9879\u76ee\u3002<\/p>\n<p><img style=\"max-width:90%\"> <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528\u906e\u7f69\u52a8\u753b\u5b9e\u73b0 Vue 3 \u4e2d\u7684\u56fe\u50cf\u8f6e\u64ad\u6548\u679c\uff1f\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>\u5b9e\u73b0\u56fe\u50cf\u8f6e\u64ad\u6548\u679c\u7684 3 \u89e3\u51b3\u65b9\u6848 \u4f60\u9047\u5230\u7684\u95ee\u9898\u662f\u6839\u636e\u63d0\u4f9b\u7684\u7f51\u7ad9\u793a\u4f8b\uff0c\u5728 Vue 3 \u4e2d\u5b9e\u73b0\u56fe\u50cf\u81ea\u52a8\u5207\u6362\u6548\u679c\u3002\u7f51\u7ad9\u4e0a\u7684\u6548\u679c\u662f\u901a\u8fc7\u4f7f\u7528\u4e24\u4e2a\u5e26\u6709\u201canimation\u201d\u7c7b\u7684\u76d2\u5b50\u6765\u5b9e\u73b0\u7684\u3002 \u89e3\u51b3\u65b9\u6848\uff1a\u906e\u7f69\u52a8\u753b \u8981\u89e3\u51b3\u4f60\u7684\u95ee\u9898\uff0c\u4e00\u79cd\u53ef\u884c\u7684\u89e3\u51b3\u65b9\u6848\u662f\u4f7f\u7528\u906e\u7f69\u52a8\u753b\u3002\u906e\u7f69\u52a8\u753b\u662f\u4e00\u79cd\u901a\u8fc7\u5728\u5143\u7d20\u4e0a\u6dfb\u52a0\u8def\u5f84\u6765\u521b\u5efa\u6548\u679c\u7684\u6280\u672f\uff0c\u8be5\u8def\u5f84\u4f1a\u6cbf\u7740\u8be5\u8def\u5f84\u79fb\u52a8\u3002 \u5b9e\u73b0\u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5c06\u4e00\u4e2a\u906e\u7f69\u6dfb\u52a0\u5230\u6700\u4e0a\u5c42\u7684\u56fe\u50cf\u3002 \u5728\u906e\u7f69\u4e0a\u8bbe\u7f6e\u8def\u5f84\u52a8\u753b\u3002 \u5f53\u8def\u5f84\u52a8\u753b\u5b8c\u6210\u540e\uff0c\u5207\u6362\u6700\u4e0a\u5c42\u7684\u56fe\u50cf\u3002 \u4ee3\u7801\u793a\u4f8b\uff1a &lt;div class=&#8221;shop-card&#8221;&gt; &lt;div class=&#8221;mask&#8221;&gt; &lt;svg&gt; &lt;path d=&#8221;M 0 0 L 100% 0 L 100% 100% L 0 100% Z&#8221; \/&gt; &lt;\/svg&gt; &lt;\/div&gt; @@##@@ &lt;\/div&gt; \u767b\u5f55\u540e\u590d\u5236 .mask { position: absolute; width: 100%; height: 100%; overflow: hidden; } .mask path { stroke: [&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-27893","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27893","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=27893"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27893\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27893"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27893"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27893"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}