{"id":2772,"date":"2024-11-10T13:39:36","date_gmt":"2024-11-10T05:39:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2772\/"},"modified":"2024-11-10T13:39:36","modified_gmt":"2024-11-10T05:39:36","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-vue-3-%e9%a1%b9%e7%9b%ae%e4%b8%ad%e9%92%88%e5%af%b9%e7%89%b9%e5%ae%9a%e9%a1%b5%e9%9d%a2%e5%ae%9e%e7%8e%b0%e5%83%8f%e7%b4%a0%e5%88%b0-rem-%e7%9a%84%e8%87%aa%e9%80%82","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2772\/","title":{"rendered":"\u5982\u4f55\u5728 Vue 3 \u9879\u76ee\u4e2d\u9488\u5bf9\u7279\u5b9a\u9875\u9762\u5b9e\u73b0\u50cf\u7d20\u5230 rem \u7684\u81ea\u9002\u5e94\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173087695839581.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 Vue 3 \u9879\u76ee\u4e2d\u9488\u5bf9\u7279\u5b9a\u9875\u9762\u5b9e\u73b0\u50cf\u7d20\u5230 rem \u7684\u81ea\u9002\u5e94\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 Vue 3 \u9879\u76ee\u4e2d\u9488\u5bf9\u7279\u5b9a\u9875\u9762\u5b9e\u73b0\u50cf\u7d20\u5230 rem \u7684\u81ea\u9002\u5e94\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728  3 \u4e2d\u9488\u5bf9\u7279\u5b9a\u9875\u9762\u5b9e\u73b0\u50cf\u7d20\u5230 rem \u7684\u81ea\u9002\u5e94<\/strong><\/p>\n<p>\u5728 Vue \u9879\u76ee\u4e2d\uff0c\u9700\u8981\u5728\u4e00\u4e2a\u7279\u5b9a\u9875\u9762\u5b9e\u73b0\u50cf\u7d20\u5230 rem \u7684\u81ea\u9002\u5e94\uff0c\u4ee5\u6839\u636e 1920 \u7684\u8bbe\u8ba1\u56fe\u81ea\u52a8\u8ba1\u7b97\u5e76\u8f6c\u6362\u50cf\u7d20\u503c\uff0c\u800c\u53c8\u4e0d\u5f71\u54cd\u6574\u4e2a\u9879\u76ee\u7684 UI \u6846\u67b6\u3002<\/p>\n<p>\u9488\u5bf9\u6b64\u9700\u6c42\uff0c\u63a8\u8350\u4f7f\u7528\u4e00\u79cd\u52a8\u6001\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\u7684\u65b9\u6cd5\u3002\u5229\u7528 jQuery \u83b7\u5f97\u9875\u9762\u7684\u5bbd\u5ea6\uff0c\u5e76\u4ee5 375 \u4f5c\u4e3a\u57fa\u51c6\u503c\uff0c\u901a\u8fc7\u4e00\u4e2a VScode \u63d2\u4ef6 px2rem \u8fdb\u884c\u8f6c\u6362\u3002\u5177\u4f53\u5b9e\u73b0\u5982\u4e0b\uff1a<\/p>\n<p>\u9996\u5148\u5728\u9996\u9875\u7684 mounted \u94a9\u5b50\u4e2d\uff0c\u5f15\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>let appWidth = $('#app').width()\nlet size = (appWidth \/ 375) * 10\ndocument.documentElement.style.fontSize = size + 'px';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u9700\u8981\u6839\u636e\u5b9e\u9645\u9879\u76ee\u4fee\u6539\u57fa\u51c6\u503c\u3002\u4ee5 html \u5143\u7d20\u7684 font-size \u4e3a 10px \u4e3a\u4f8b\uff0c\u8fd9\u6837\u5176\u4ed6\u5355\u4f4d\u8f6c\u6362\u4e3a rem \u65f6\u66f4\u65b9\u4fbf\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5b9e\u73b0\u53ea\u5bf9\u5f53\u524d\u9875\u9762\u5e94\u7528\u50cf\u7d20\u5230 rem \u7684\u81ea\u9002\u5e94\uff0c\u800c\u4e0d\u4f1a\u5bf9\u6574\u4e2a\u9879\u76ee\u4ea7\u751f\u5f71\u54cd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 Vue 3 \u9879\u76ee\u4e2d\u9488\u5bf9\u7279\u5b9a\u9875\u9762\u5b9e\u73b0\u50cf\u7d20\u5230 rem \u7684\u81ea\u9002\u5e94\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>\u5728 3 \u4e2d\u9488\u5bf9\u7279\u5b9a\u9875\u9762\u5b9e\u73b0\u50cf\u7d20\u5230 rem \u7684\u81ea\u9002\u5e94 \u5728 Vue \u9879\u76ee\u4e2d\uff0c\u9700\u8981\u5728\u4e00\u4e2a\u7279\u5b9a\u9875\u9762\u5b9e\u73b0\u50cf\u7d20\u5230 rem \u7684\u81ea\u9002\u5e94\uff0c\u4ee5\u6839\u636e 1920 \u7684\u8bbe\u8ba1\u56fe\u81ea\u52a8\u8ba1\u7b97\u5e76\u8f6c\u6362\u50cf\u7d20\u503c\uff0c\u800c\u53c8\u4e0d\u5f71\u54cd\u6574\u4e2a\u9879\u76ee\u7684 UI \u6846\u67b6\u3002 \u9488\u5bf9\u6b64\u9700\u6c42\uff0c\u63a8\u8350\u4f7f\u7528\u4e00\u79cd\u52a8\u6001\u8c03\u6574\u5b57\u4f53\u5927\u5c0f\u7684\u65b9\u6cd5\u3002\u5229\u7528 jQuery \u83b7\u5f97\u9875\u9762\u7684\u5bbd\u5ea6\uff0c\u5e76\u4ee5 375 \u4f5c\u4e3a\u57fa\u51c6\u503c\uff0c\u901a\u8fc7\u4e00\u4e2a VScode \u63d2\u4ef6 px2rem \u8fdb\u884c\u8f6c\u6362\u3002\u5177\u4f53\u5b9e\u73b0\u5982\u4e0b\uff1a \u9996\u5148\u5728\u9996\u9875\u7684 mounted \u94a9\u5b50\u4e2d\uff0c\u5f15\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a let appWidth = $(&#8216;#app&#8217;).width() let size = (appWidth \/ 375) * 10 document.documentElement.style.fontSize = size + &#8216;px&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0c\u9700\u8981\u6839\u636e\u5b9e\u9645\u9879\u76ee\u4fee\u6539\u57fa\u51c6\u503c\u3002\u4ee5 html \u5143\u7d20\u7684 font-size \u4e3a 10px \u4e3a\u4f8b\uff0c\u8fd9\u6837\u5176\u4ed6\u5355\u4f4d\u8f6c\u6362\u4e3a rem \u65f6\u66f4\u65b9\u4fbf\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5b9e\u73b0\u53ea\u5bf9\u5f53\u524d\u9875\u9762\u5e94\u7528\u50cf\u7d20\u5230 [&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-2772","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2772","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=2772"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2772\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}