在Vue项目中将px转换为rem以实现移动端适配(经测试有效)
发布时间
阅读量:
阅读量
近期在项目开发过程中遇到一个具体需求:在Vue PC端应用中需要集成移动端页面,其中涉及到将像素单位转换为rem单位以实现移动端适配的问题,以下是两个步骤的解决方案,下面将为大家详细介绍。
1. 在index.html页面中引入px转rem的通用处理方法

(function () {
function resizeBaseFontSize() {
var rootHtml = document.documentElement,
deviceWidth = rootHtml.clientWidth;
if (deviceWidth > 640) {
deviceWidth = 640;
}
rootHtml.style.fontSize = deviceWidth / 7.5 + "px";
}
resizeBaseFontSize();
windo
全部评论 (0)
还没有任何评论哟~
