{"id":63,"date":"2024-02-02T19:46:16","date_gmt":"2024-02-02T11:46:16","guid":{"rendered":"https:\/\/ishht.com\/?p=63"},"modified":"2024-02-02T19:49:10","modified_gmt":"2024-02-02T11:49:10","slug":"vue%e4%b8%ad%e4%bd%bfpx%e8%87%aa%e5%8a%a8%e8%bd%acrem%e9%85%8d%e7%bd%ae-h5%e9%80%82%e9%85%8d%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/ishht.com\/?p=63","title":{"rendered":"Vue\u4e2d\u4f7fpx\u81ea\u52a8\u8f6crem\u914d\u7f6e (h5\u9002\u914d\u95ee\u9898)"},"content":{"rendered":"<p>\u4ee5\u4e0b\u65b9\u6cd5\u4e3apx\u81ea\u52a8\u8f6c\u6362rem\uff0c\u987e\u540d\u601d\u4e49\uff0c\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u4e0d\u7528\u518d\u5173\u5fc3rem\u6362\u7b97\u7b49\u7b49\uff0c\u53ea\u9700\u6309\u7167\u8bbe\u8ba1\u7a3f\u7684px\u503c\u5199\u5165\u5373\u53ef\uff0c\u5f53\u4f60\u4fdd\u5b58\u540ePostCSS\u63d2\u4ef6\u4f1a\u81ea\u52a8\u5c06px\u8f6c\u6362\u6210\u6240\u914d\u7f6e\u7684rem\u503c\uff0c\u5e76\u4e14\u4f60\u5728\u6d4f\u89c8\u63a7\u5236\u53f0\u89c2\u6d4b\u754c\u9762\u65f6\u4f60\u4f1a\u53d1\u73b0\u4f60\u5728\u4ee3\u7801\u91cc\u5199\u7684\u662fpx\u5355\u4f4d\uff0c\u5728\u63a7\u5236\u53f0\u88ab\u8f6c\u6362\u6210\u4e86rem\u5355\u4f4d\u3002<\/p>\n<p>postcss \u4e00\u79cd\u5bf9css\u7f16\u8bd1\u7684\u5de5\u5177\uff0c\u672c\u8eab\u4e0d\u4f1a\u5bf9css\u4e00\u987f\u64cd\u4f5c\uff0c\u5b83\u901a\u8fc7\u63d2\u4ef6\u5b9e\u73b0\u529f\u80fd\u3002<br \/>\n1. \u4f7f\u7528amfe-flexible + postcss-pxtorem\u5305\u5b9e\u73b0px\u81ea\u52a8\u8f6c\u6362rem<br \/>\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n<p><span>1.\u9996\u5148\u4e0b\u8f7d\u9700\u8981\u7684npm\u5305<\/span><\/p>\n<pre class=\"corepress-code-pre\"><code>npm i amfe-flexible\r\nnpm install postcss-pxtorem -D<\/code><\/pre>\n<ul>\n<li><strong>\u8be5\u63d2\u4ef6\u4e0d\u80fd\u8f6c\u6362\u884c\u5185\u6837\u5f0f\u4e2d\u7684 px\uff0c\u4f8b\u5982 &lt;div style=&#8221;width: 200px;&#8221;&gt;&lt;\/div&gt;<\/strong><\/li>\n<\/ul>\n<p><strong>2 \u5bf9\u6587\u4ef6\u8fdb\u884c\u989d\u5916\u7684\u914d\u7f6e<\/strong><\/p>\n<ul>\n<li><strong>\u9996\u5148\u5728<code>mian.js<\/code>\u5f15\u5165<code>amfe-flexible<\/code><\/strong><\/li>\n<\/ul>\n<pre class=\"corepress-code-pre\"><code>import 'amfe-flexible'\r\n<\/code><\/pre>\n<p>3.\u5728\u4e0esrc\u6587\u4ef6\u5939\u5e73\u7ea7\u533a\u57df\u521b\u5efa\u4e00\u4e2a\u4e3a.postcssrc.js\u7684\u6587\u4ef6<br \/>\n\u5bf9.postcssrc.js\u6587\u4ef6\u8fdb\u884c\u989d\u5916\u914d\u7f6e<br \/>\nautoprefixer \u662f\u4e00\u4e2a\u81ea\u52a8\u6dfb\u52a0\u6d4f\u89c8\u5668\u524d\u7f00\u7684 PostCss \u63d2\u4ef6\uff0cbrowsers \u7528\u6765\u914d\u7f6e\u517c\u5bb9\u7684\u6d4f\u89c8\u5668\u7248\u672c\u4fe1\u606f\uff0c\u4f46\u662f\u5199\u5728\u8fd9\u91cc\u7684\u8bdd\u4f1a\u5f15\u8d77\u7f16\u8bd1\u5668\u8b66\u544a\u3002\u56e0\u4e3a VueCLI \u5185\u90e8\u5df2\u7ecf\u914d\u7f6e\u4e86 autoprefixer \u63d2\u4ef6\u3002<br \/>\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\n<pre class=\"corepress-code-pre\"><code>module.exports = {\r\n    \"plugins\": {\r\n      'postcss-pxtorem': {\r\n        rootValue: 37.5,\r\n        propList: ['*']\r\n      }\r\n    }\r\n  }<\/code><\/pre>\n<p><span>\u8f6c\u8f7d\uff1a<\/span><a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/www.jianshu.com\/p\/67a29794b98b\" rel=\"nofollow\" title=\"Vue\u4e2d\u4f7fpx\u81ea\u52a8\u8f6crem\u914d\u7f6e\uff08\u4f7f\u7528\u7b2c\u4e09\u65b9\u5305\uff09|| \u7528js\u914d\u7f6e+Vscode\u6269\u5c55\u5904\u7406\u9002\u914d\u95ee\u9898 - \u7b80\u4e66 (jianshu.com)\">Vue\u4e2d\u4f7fpx\u81ea\u52a8\u8f6crem\u914d\u7f6e\uff08\u4f7f\u7528\u7b2c\u4e09\u65b9\u5305\uff09|| \u7528js\u914d\u7f6e+Vscode\u6269\u5c55\u5904\u7406\u9002\u914d\u95ee\u9898 &#8211; \u7b80\u4e66 (jianshu.com)<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0b\u65b9\u6cd5\u4e3apx\u81ea\u52a8\u8f6c\u6362rem\uff0c\u987e\u540d\u601d\u4e49\uff0c\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u4e0d\u7528\u518d\u5173\u5fc3rem\u6362\u7b97\u7b49\u7b49\uff0c\u53ea\u9700\u6309\u7167\u8bbe\u8ba1\u7a3f\u7684px\u503c\u5199\u5165\u5373\u53ef\uff0c\u5f53\u4f60\u4fdd\u5b58\u540ePostCSS\u63d2\u4ef6\u4f1a\u81ea\u52a8\u5c06px\u8f6c\u6362\u6210\u6240\u914d\u7f6e\u7684rem\u503c\uff0c\u5e76\u4e14\u4f60\u5728\u6d4f\u89c8\u63a7\u5236\u53f0\u89c2\u6d4b\u754c\u9762\u65f6\u4f60\u4f1a\u53d1\u73b0\u4f60\u5728\u4ee3\u7801\u91cc\u5199\u7684\u662fpx\u5355\u4f4d\uff0c\u5728\u63a7\u5236\u53f0\u88ab\u8f6c\u6362\u6210\u4e86rem\u5355\u4f4d\u3002 postcss \u4e00\u79cd\u5bf9css\u7f16\u8bd1\u7684\u5de5\u5177\uff0c\u672c\u8eab\u4e0d\u4f1a\u5bf9css\u4e00\u987f\u64cd\u4f5c\uff0c\u5b83\u901a\u8fc7\u63d2\u4ef6\u5b9e\u73b0\u529f\u80fd\u3002 1. \u4f7f\u7528amfe-flexible + postcss-pxtorem\u5305\u5b9e\u73b0px\u81ea\u52a8\u8f6c\u6362rem \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 1.\u9996\u5148\u4e0b\u8f7d\u9700\u8981\u7684npm\u5305 npm i amfe-flexible npm install postcss-pxtorem -D \u8be5\u63d2\u4ef6\u4e0d\u80fd\u8f6c\u6362\u884c\u5185\u6837\u5f0f\u4e2d\u7684 px\uff0c\u4f8b\u5982 &lt;div style=&#8221;width: 200px;&#8221;&gt;&lt;\/div&gt; 2 \u5bf9\u6587\u4ef6\u8fdb\u884c\u989d\u5916\u7684\u914d\u7f6e \u9996\u5148\u5728mian.js\u5f15\u5165amfe-flexible import &#8216;amfe-flexible&#8217; 3.\u5728\u4e0esrc\u6587\u4ef6\u5939\u5e73\u7ea7\u533a\u57df\u521b\u5efa\u4e00\u4e2a\u4e3a.postcssrc.js\u7684\u6587\u4ef6 \u5bf9.postcssrc.js\u6587\u4ef6\u8fdb\u884c\u989d\u5916\u914d\u7f6e autoprefixer \u662f\u4e00\u4e2a\u81ea\u52a8\u6dfb\u52a0\u6d4f\u89c8\u5668\u524d\u7f00\u7684 PostCss \u63d2\u4ef6\uff0cbrowsers \u7528\u6765\u914d\u7f6e\u517c\u5bb9\u7684\u6d4f\u89c8\u5668\u7248\u672c\u4fe1\u606f\uff0c\u4f46\u662f\u5199\u5728\u8fd9\u91cc\u7684\u8bdd\u4f1a\u5f15\u8d77\u7f16\u8bd1\u5668\u8b66\u544a\u3002\u56e0\u4e3a VueCLI \u5185\u90e8\u5df2\u7ecf\u914d\u7f6e\u4e86 autoprefixer \u63d2\u4ef6\u3002 \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014 module.exports = { &#8220;plugins&#8221;: { &#8216;postcss-pxtorem&#8217;: { rootValue: 37.5, propList: [&#8216;*&#8217;] } } } \u8f6c\u8f7d\uff1aVue\u4e2d\u4f7fpx\u81ea\u52a8\u8f6crem\u914d\u7f6e\uff08\u4f7f\u7528\u7b2c\u4e09\u65b9\u5305\uff09|| \u7528js\u914d\u7f6e+Vscode\u6269\u5c55\u5904\u7406\u9002\u914d\u95ee\u9898 &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-63","post","type-post","status-publish","format-standard","hentry","category-dm"],"_links":{"self":[{"href":"https:\/\/ishht.com\/index.php?rest_route=\/wp\/v2\/posts\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ishht.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ishht.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ishht.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ishht.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=63"}],"version-history":[{"count":0,"href":"https:\/\/ishht.com\/index.php?rest_route=\/wp\/v2\/posts\/63\/revisions"}],"wp:attachment":[{"href":"https:\/\/ishht.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=63"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ishht.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=63"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ishht.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}