vue2如何适配移动端
时间: 2023-11-16 08:59:42 浏览: 99
为适配移动端,我们可以使用postcss-pxtorem插件将像素单位转换为rem单位。在Vue2中,我们可以在vue.config.js文件中进行配置。具体步骤如下:
1. 安装postcss-pxtorem插件:npm install postcss-pxtorem --save-dev
2. 在vue.config.js文件中添加以下代码:
module.exports = {
css: {
loaderOptions: {
postcss: {
plugins: {
"postcss-pxtorem": {
rootValue: 75, // 设计图宽度为750px时,设置为75
propList: ["*"] // 这个*作用是width,height,margin宽高这些属性的适配,单位转换为rem
}
}
}
}
}
}
另外,我们也可以在postcss.config.js文件中进行配置,具体步骤如下:
1. 安装postcss-pxtorem插件:npm install postcss-pxtorem --save-dev
2. 在postcss.config.js文件中添加以下代码:
module.exports = {
plugins: {
"postcss-pxtorem": {
rootValue: 75, // 设计图宽度为750px时,设置为75
propList: ["*"] // 这个*作用是width,height,margin宽高这些属性的适配,单位转换为rem
}
}
}
阅读全文
相关推荐
















