{"id":1378,"date":"2024-11-10T12:06:12","date_gmt":"2024-11-10T04:06:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/1378\/"},"modified":"2024-11-10T12:06:12","modified_gmt":"2024-11-10T04:06:12","slug":"vue-3-%e9%a1%b5%e9%9d%a2%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0-px-to-rem-%e8%87%aa%e9%80%82%e5%ba%94%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/1378\/","title":{"rendered":"Vue 3 \u9875\u9762\u5982\u4f55\u5b9e\u73b0 px to rem \u81ea\u9002\u5e94\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173038446315140.jpg\" class=\"aligncenter\" title=\"Vue 3 \u9875\u9762\u5982\u4f55\u5b9e\u73b0 px to rem \u81ea\u9002\u5e94\uff1f\u63d2\u56fe\" alt=\"Vue 3 \u9875\u9762\u5982\u4f55\u5b9e\u73b0 px to rem \u81ea\u9002\u5e94\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728  3 \u9875\u9762\u4e2d\u5b9e\u73b0 px to rem \u81ea\u9002\u5e94\uff1f<\/strong><\/p>\n<p>\u5728 vue \u9879\u76ee\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u8ba9\u7279\u5b9a\u7684\u9875\u9762\u8fdb\u884c px to rem \u81ea\u9002\u5e94\uff0c\u4ee5\u5b9e\u73b0\u81ea\u52a8\u7f29\u653e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u53ef\u7528\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p>\u4f7f\u7528 javascript \u83b7\u53d6\u9875\u9762\u5bbd\u5ea6\uff0c\u5e76\u4ee5 375px \u4f5c\u4e3a\u57fa\u51c6\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>let appwidth = $('#app').width()<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\uff0c\u4f7f\u7528  \u4e2d\u7684 px2rem \u63d2\u4ef6\u8ba1\u7b97\u6bcf\u4e2a\u5355\u4f4d\u76f8\u5bf9\u4e8e\u57fa\u51c6\u503c\u7684 rem \u503c\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>let size = (appwidth \/ 375) * 10<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6700\u540e\uff0c\u5728\u9875\u9762 mounted \u94a9\u5b50\u51fd\u6570\u4e2d\uff0c\u8bbe\u7f6e html \u5143\u7d20\u7684 font-size \u4e3a\u8ba1\u7b97\u51fa\u7684 rem \u503c\u3002<\/p>\n<pre>document.documentElement.style.fontSize = size + 'px';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6837\uff0c\u9875\u9762\u4e2d\u7684\u5355\u4f4d\u5c06\u6839\u636e\u6d4f\u89c8\u5668\u7a97\u53e3\u5927\u5c0f\u81ea\u52a8\u8f6c\u6362\u4e3a rem\uff0c\u4ece\u800c\u5b9e\u73b0\u81ea\u9002\u5e94\u5e03\u5c40\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fVue 3 \u9875\u9762\u5982\u4f55\u5b9e\u73b0 px to rem \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>\u5982\u4f55\u5728 3 \u9875\u9762\u4e2d\u5b9e\u73b0 px to rem \u81ea\u9002\u5e94\uff1f \u5728 vue \u9879\u76ee\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u8ba9\u7279\u5b9a\u7684\u9875\u9762\u8fdb\u884c px to rem \u81ea\u9002\u5e94\uff0c\u4ee5\u5b9e\u73b0\u81ea\u52a8\u7f29\u653e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u53ef\u7528\u7684\u89e3\u51b3\u65b9\u6848\uff1a \u4f7f\u7528 javascript \u83b7\u53d6\u9875\u9762\u5bbd\u5ea6\uff0c\u5e76\u4ee5 375px \u4f5c\u4e3a\u57fa\u51c6\u503c\u3002\u4f8b\u5982\uff1a let appwidth = $(&#8216;#app&#8217;).width() \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\uff0c\u4f7f\u7528 \u4e2d\u7684 px2rem \u63d2\u4ef6\u8ba1\u7b97\u6bcf\u4e2a\u5355\u4f4d\u76f8\u5bf9\u4e8e\u57fa\u51c6\u503c\u7684 rem \u503c\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b let size = (appwidth \/ 375) * 10 \u767b\u5f55\u540e\u590d\u5236 \u6700\u540e\uff0c\u5728\u9875\u9762 mounted \u94a9\u5b50\u51fd\u6570\u4e2d\uff0c\u8bbe\u7f6e html \u5143\u7d20\u7684 font-size \u4e3a\u8ba1\u7b97\u51fa\u7684 rem \u503c\u3002 document.documentElement.style.fontSize = size + &#8216;px&#8217;; \u767b\u5f55\u540e\u590d\u5236 [&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-1378","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1378","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=1378"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/1378\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=1378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=1378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=1378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}