{"id":1281,"date":"2024-05-16T09:40:57","date_gmt":"2024-05-16T01:40:57","guid":{"rendered":"http:\/\/ericw.top\/?p=1281"},"modified":"2024-05-31T08:39:18","modified_gmt":"2024-05-31T00:39:18","slug":"%e9%9f%b3%e9%a2%91%e6%92%ad%e6%94%be%e5%99%a8%e7%bb%84%e4%bb%b6-%e5%bc%80%e5%8f%91%e6%96%87%e6%a1%a3","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=1281","title":{"rendered":"\u97f3\u9891\u64ad\u653e\u5668\u7ec4\u4ef6 \u2014 \u5f00\u53d1\u6587\u6863"},"content":{"rendered":"\n<p>\u9996\u5148\uff0c\u8981\u4f7f\u7528<code class=\"prettyprint\" >ref<\/code>\u5c06<code class=\"prettyprint\" >&lt;video&gt;<\/code>\u6807\u7b7e\u8fdb\u884c\u7ed1\u5b9a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const audioCtr = ref(null)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;video src=&quot;#&quot; ref=&quot;audioCtr&quot; autoplay&gt;&lt;\/video&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-0\">\u4e00\u3001\u64ad\u653e\/\u6682\u505c<\/h2>\n\n\n\n<p>\u8981\u5b9e\u73b0\u64ad\u653e\u6682\u505c\u529f\u80fd\uff0c\u9700\u8981\u6dfb\u52a0\u4e24\u4e2a\u65b9\u6cd5\uff0c\u4e00\u4e2a\u662f\u64ad\u653e\u65b9\u6cd5\uff0c\u4e00\u4e2a\u662f\u6682\u505c\u65b9\u6cd5\uff0c\u4f7f\u7528\u7684\u662fvideo\u6807\u7b7e\u81ea\u5e26\u7684\u65b9\u6cd5\uff0c\u6765\u5b9e\u73b0\u64ad\u653e\u5668\u5185\u90e8\u7684\u6682\u505c\u548c\u64ad\u653e\u3002<\/p>\n\n\n\n<p>\u7136\u540e\u6dfb\u52a0\u4e00\u4e2a\u6682\u505c\u64ad\u653e\u7684icon\u56fe\u6807\uff0c\u7ed1\u5b9a\u4e00\u4e2a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63a7\u5236\u64ad\u653e\u5668\u7684\u6682\u505c\u548c\u64ad\u653e<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"551\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-1-1024x551.png\" alt=\"\" class=\"wp-image-1287\" style=\"width:758px;height:auto\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-1-1024x551.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-1-300x161.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-1-768x413.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-1.png 1242w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const isPlay = ref(false)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;video src=&quot;#&quot; ref=&quot;audioCtr&quot; autoplay @play=&quot;playFn&quot;@pause=&quot;pauseFn&quot;&gt;&lt;\/video&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;div class=&quot;status&quot; @click=&quot;changePlayStatus&quot;&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/\/ \u6539\u53d8\u64ad\u653e\u72b6\u6001\r\nfunction changePlayStatus() {\r\n    if (!audioCtr.value) return\r\n    if (isPlay.value) {\r\n        audioCtr.value.pause()\r\n    } else {\r\n        audioCtr.value.play()\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/\/ \u76d1\u542c\u5f00\u59cb\u4e8b\u4ef6\r\nfunction playFn(e) {\r\n    console.log(&#039;\u5f00\u542f\u64ad\u653e\u72b6\u6001&#039;);\r\n    isPlay.value = true\r\n    emit(&#039;play&#039;, e)\r\n}\r\n\/\/ \u76d1\u542c\u6682\u505c\u4e8b\u4ef6\r\nfunction pauseFn(e) {\r\n    console.log(&#039;\u6682\u505c\u64ad\u653e\u72b6\u6001&#039;);\r\n    isPlay.value = false\r\n    emit(&#039;pause&#039;, e)\r\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-1\">\u4e8c\u3001\u4e0a\u4e00\u66f2\/\u4e0b\u4e00\u66f2<\/h2>\n\n\n\n<p>\u9996\u5148\uff0c\u6dfb\u52a0\u4e24\u4e2aicon\u56fe\u6807\uff0c\u7ed1\u5b9a\u4e24\u4e2a\u65b9\u6cd5\uff0c\u7136\u540e\u6539\u53d8\u5f53\u524d\u64ad\u653e\u6b4c\u66f2\u7684\u4e0b\u6807\uff0c\u7136\u540e\u505a\u4e00\u4e2awatch\u76d1\u542c\uff0c\u4e0b\u6807\u6539\u53d8\u65f6\u5c31\u4f1a\u81ea\u52a8\u5207\u6b4c\uff0c\u64ad\u653e\u5668\u5185\u90e8\u4f1a\u53d8\u5316\u64ad\u653e\u7684\u6b4c\u66f2\uff0c\u4f8b\u5982\u4e0b\u6807 + + \u5c31\u662f\u4e0b\u4e00\u66f2\uff0c\u4e0b\u6807 - - \u5c31\u662f\u4e0b\u4e00\u66f2\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"551\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-2-1024x551.png\" alt=\"\" class=\"wp-image-1288\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-2-1024x551.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-2-300x161.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-2-768x413.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-2.png 1242w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;i class=&quot;iconfont icon-shangyiqu&quot; @click=&quot;preSong&quot;&gt;&lt;\/i&gt;\r\r\n&lt;i class=&quot;iconfont icon-xiayiqu&quot; @click=&quot;nextSong&quot;&gt;&lt;\/i&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/\/ \u4e0b\u6807\u53d1\u751f\u6539\u53d8 \u81ea\u52a8\u5207\u6b4c\r\nwatch(playingIndex, (newVal, oldVal) =&gt; {\r\n    setPlayingInfoByIndex(newVal)\r\n    emit(&#039;change&#039;, newVal)\r\n})\r\n\r\n\/\/ \u4e0a\u4e00\u66f2\r\nfunction preSong() {\r\n    if (loopType.value != 2) {\r\n        if (playingIndex.value &lt;= 0) {\r\n            playingIndex.value = prop.srcList.length - 1\r\n            return\r\n        }\r\n        playingIndex.value--\r\n    } else {\r\n        loopDict&#091;loopType.value].fn()\r\n    }\r\n}\r\n\/\/ \u4e0b\u4e00\u66f2\r\nfunction nextSong() {\r\n    if (loopType.value != 2) {\r\n        if (playingIndex.value &gt;= prop.srcList.length - 1) {\r\n            playingIndex.value = 0\r\n            return\r\n        }\r\n        playingIndex.value++\r\n    } else {\r\n        loopDict&#091;loopType.value].fn()\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-2\">\u4e09\u3001\u5217\u8868\u5faa\u73af\/\u968f\u673a\u5faa\u73af\/\u5355\u66f2\u5faa\u73af<\/h2>\n\n\n\n<p>\u9996\u5148\u6709\u4e00\u4e2a\uff0c\u5bf9\u8c61\u6570\u7ec4\uff0c\u91cc\u9762\u5305\u542b\u4e86\uff0c\u4e09\u79cd\u72b6\u6001\u7684\u7c7b\u578b\u4e0b\u6807\u3001css\u56fe\u8868\u6837\u5f0f\u3001\u5bf9\u5e94\u64ad\u653e\u6a21\u5f0f\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >const loopDict = &#091;\r\n    {\r\n        type: 0,\r\n        css: &#039;iconfont icon-liebiaoxunhuan&#039;,\r\n        fn: () =&gt; {\r\n            nextSong()\r\n        }\r\n    },\r\n    {\r\n        type: 1,\r\n        css: &#039;iconfont icon-danquxunhuan&#039;,\r\n        fn: () =&gt; {\r\n            audioCtr.value.src = &#039;#&#039;\r\n            setPlayingInfoByIndex(playingIndex.value)\r\n        }\r\n    },\r\n    {\r\n        type: 2,\r\n        css: &#039;iconfont icon-suijibofang&#039;,\r\n        fn: () =&gt; {\r\n            while (true) {\r\n                const newIndex = Math.floor(prop.srcList.length * Math.random())\r\n                if (playingIndex.value != newIndex) {\r\n                    playingIndex.value = newIndex;\r\n                    break;\r\n                }\r\n            }\r\n        }\r\n    }\r\n]<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\u5c06\u4ed6\u4eec\u7ed1\u5b9a\u5728\u4e00\u4e2adiv\u91cc\u9762\uff0c\u4f7f\u4ed6\u53ef\u4ee5\u70b9\u51fb\u66f4\u6362\u4e0d\u540c\u7684\u6837\u5f0f\u548c\u65b9\u6cd5\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"551\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-3-1024x551.png\" alt=\"\" class=\"wp-image-1290\" srcset=\"http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-3-1024x551.png 1024w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-3-300x161.png 300w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-3-768x413.png 768w, http:\/\/ericw.top\/wp-content\/uploads\/2024\/05\/image-3.png 1516w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;div class=&quot;loop&quot; @click=&quot;changeLoop&quot;&gt;\r\n  &lt;i :class=&quot;loopDis&quot;&gt;&lt;\/i&gt;\r\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/\/ \u66f4\u65b0\u5faa\u73af\u65b9\u6848\r\nfunction changeLoop() {\r\n    let index = loopDict.findIndex(i =&gt; i.type == loopType.value)\r\n    if (index == loopDict.length - 1) {\r\n        loopType.value = 0\r\n    } else {\r\n        loopType.value++\r\n    }\r\n    emit(&#039;uploop&#039;, loopType.value)\r\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-3\">\u56db\u3001\u81ea\u52a8\u64ad\u653e<\/h2>\n\n\n\n<p>\u4f7f\u4e00\u9996\u6b4c\u64ad\u653e\u7ed3\u675f\u4ee5\u540e\uff0c\u53ef\u4ee5\u81ea\u52a8\u64ad\u653e\u4e0b\u4e00\u9996\u6b4c\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u8981\u505a\u4e00\u4e2a\u64ad\u653e\u7ed3\u675f\u4ee5\u540e\u89e6\u53d1\u7684\u65b9\u6cd5\uff0c\u4e4b\u540e\u8fd8\u8981\u7ed9<code class=\"prettyprint\" >video<\/code>\u6807\u7b7e\u6dfb\u52a0<code class=\"prettyprint\" >autoplay<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >&lt;video src=&quot;#&quot; ref=&quot;audioCtr&quot; autoplay @play=&quot;playFn&quot; @timeupdate=&quot;timeupdateFn&quot; @canplay=&quot;canplayFn&quot; @pause=&quot;pauseFn&quot; @ended=&quot;endedFn&quot;&gt;&lt;\/video&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/\/ \u64ad\u653e\u5b8c\u6210\u7684\u56de\u8c03\u4e8b\u4ef6\r\nfunction endedFn() {\r\n    loopDict&#091;loopType.value].fn()\r\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc-4\">\u4e94\u3001\u81ea\u9002\u5e94\u65b9\u6848<\/h2>\n\n\n\n<p>\u4f7f\u7528VW\u9002\u914d\u65b9\u6848\uff0c\u9700\u8981\u4e0b\u8f7dpostcss-px-to-viewport\u63d2\u4ef6<\/p>\n\n\n\n<p>\u7136\u540e\u6dfb\u52a0\u914d\u7f6e\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"prettyprint\" >\/\/ postcss.config.js\r\nexport default {\r\n    plugins: {\r\n        &#039;postcss-px-to-viewport&#039;: {\r\n            viewportWidth: 375,\r\n        },\r\n    },\r\n};\r\n\n\u4e4b\u540e\uff0c\u6211\u4eec\u5728css\u4e2d\u8f93\u5165px\uff0c\u4f1a\u81ea\u52a8\u5e2e\u6211\u4eec\u8f6c\u6362\u4e3avw\u3002<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9996\u5148\uff0c\u8981\u4f7f\u7528ref\u5c06&lt;video&gt;\u6807\u7b7e\u8fdb\u884c\u7ed1\u5b9a \u4e00\u3001\u64ad\u653e\/\u6682\u505c \u8981\u5b9e\u73b0\u64ad\u653e\u6682\u505c\u529f\u80fd\uff0c\u9700\u8981\u6dfb\u52a0\u4e24\u4e2a\u65b9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1281"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1281"}],"version-history":[{"count":7,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1281\/revisions"}],"predecessor-version":[{"id":1292,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/1281\/revisions\/1292"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1281"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}