{"id":2826,"date":"2024-11-10T10:02:09","date_gmt":"2024-11-10T02:02:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/2826\/"},"modified":"2024-11-10T10:02:09","modified_gmt":"2024-11-10T02:02:09","slug":"vue3-%e9%a1%b5%e9%9d%a2%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0-px-%e8%bd%ac-rem-%e8%87%aa%e9%80%82%e5%ba%94%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/2826\/","title":{"rendered":"Vue3 \u9875\u9762\u5982\u4f55\u5b9e\u73b0 px \u8f6c rem \u81ea\u9002\u5e94\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173088752482533.jpg\" class=\"aligncenter\" title=\"Vue3 \u9875\u9762\u5982\u4f55\u5b9e\u73b0 px \u8f6c rem \u81ea\u9002\u5e94\uff1f\u63d2\u56fe\" alt=\"Vue3 \u9875\u9762\u5982\u4f55\u5b9e\u73b0 px \u8f6c rem \u81ea\u9002\u5e94\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>3\u9875\u9762\u81ea\u9002\u5e94px\u8f6crem<\/strong><\/p>\n<p>\u5728Vue3\u4e2d\uff0c\u5982\u679c\u4f60\u9700\u8981\u8ba9\u67d0\u4e2a\u7279\u5b9a\u9875\u9762\u8fdb\u884cpx\u8f6crem\u7684\u81ea\u9002\u5e94\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p>\u4e00\u4f4d\u5f00\u53d1\u8005\u63d0\u51fa\uff0c\u4f7f\u7528jQuery\u83b7\u53d6\u9875\u9762\u7684\u5bbd\u5ea6\uff0c\u5e76\u4ee5375px\u4f5c\u4e3a\u57fa\u51c6\u503c\u3002\u4ee5\u4e0b\u662f\u4ed6\u63d0\u4f9b\u7684\u4ee3\u7801\u7247\u6bb5\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\u9875\u9762\u6302\u8f7d\uff08mounted\uff09\u65f6\uff0c\u5c06\u8fd9\u6bb5\u4ee3\u7801\u6dfb\u52a0\u5230\u8be5\u7279\u5b9a\u9875\u9762\u4e2d\u3002\u5176\u4e2d\uff0c375\u662f\u57fa\u51c6\u503c\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u4f60\u7684\u9879\u76ee\u9700\u6c42\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<p>\u4e3a\u4e86\u66f4\u65b9\u4fbf\u5730\u8fdb\u884cpx\u8f6crem\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Visual Studio Code\u4e2d\u7684px2rem\u63d2\u4ef6\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u7f16\u8f91\u5668\u4e2d\u81ea\u52a8\u5c06px\u8f6c\u6362\u4e3arem\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5728Vue3\u4e2d\u5b9e\u73b0\u7279\u5b9a\u9875\u9762\u7684\u81ea\u9002\u5e94\u5927\u5c0f\uff0c\u4f7f\u5b57\u4f53\u548c\u95f4\u8ddd\u6839\u636e\u4e0d\u540c\u7684\u5c4f\u5e55\u5206\u8fa8\u7387\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fVue3 \u9875\u9762\u5982\u4f55\u5b9e\u73b0 px \u8f6c 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>3\u9875\u9762\u81ea\u9002\u5e94px\u8f6crem \u5728Vue3\u4e2d\uff0c\u5982\u679c\u4f60\u9700\u8981\u8ba9\u67d0\u4e2a\u7279\u5b9a\u9875\u9762\u8fdb\u884cpx\u8f6crem\u7684\u81ea\u9002\u5e94\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u4e00\u4f4d\u5f00\u53d1\u8005\u63d0\u51fa\uff0c\u4f7f\u7528jQuery\u83b7\u53d6\u9875\u9762\u7684\u5bbd\u5ea6\uff0c\u5e76\u4ee5375px\u4f5c\u4e3a\u57fa\u51c6\u503c\u3002\u4ee5\u4e0b\u662f\u4ed6\u63d0\u4f9b\u7684\u4ee3\u7801\u7247\u6bb5\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\u9875\u9762\u6302\u8f7d\uff08mounted\uff09\u65f6\uff0c\u5c06\u8fd9\u6bb5\u4ee3\u7801\u6dfb\u52a0\u5230\u8be5\u7279\u5b9a\u9875\u9762\u4e2d\u3002\u5176\u4e2d\uff0c375\u662f\u57fa\u51c6\u503c\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u4f60\u7684\u9879\u76ee\u9700\u6c42\u8fdb\u884c\u8c03\u6574\u3002 \u4e3a\u4e86\u66f4\u65b9\u4fbf\u5730\u8fdb\u884cpx\u8f6crem\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Visual Studio Code\u4e2d\u7684px2rem\u63d2\u4ef6\u3002\u5b83\u53ef\u4ee5\u5e2e\u52a9\u4f60\u5728\u7f16\u8f91\u5668\u4e2d\u81ea\u52a8\u5c06px\u8f6c\u6362\u4e3arem\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u901a\u8fc7\u4f7f\u7528\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5728Vue3\u4e2d\u5b9e\u73b0\u7279\u5b9a\u9875\u9762\u7684\u81ea\u9002\u5e94\u5927\u5c0f\uff0c\u4f7f\u5b57\u4f53\u548c\u95f4\u8ddd\u6839\u636e\u4e0d\u540c\u7684\u5c4f\u5e55\u5206\u8fa8\u7387\u8fdb\u884c\u8c03\u6574\u3002 \u4ee5\u4e0a\u5c31\u662fVue3 \u9875\u9762\u5982\u4f55\u5b9e\u73b0 px \u8f6c 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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-2826","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2826","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=2826"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/2826\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=2826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=2826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=2826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}