vue3+vite安装postcss-pxtorem
·
vue3+vite安装postcss-pxtorem
1、安装依赖
npm install postcss-pxtorem -D
npm install amfe-flexible -D
2、配置vite.config.ts
import postCssPxToRem from "postcss-pxtorem"
export default defineConfig({
plugins: [vue()],
css: {
postcss: {
plugins: [
postCssPxToRem({
rootValue: 75, // 设计稿尺寸 1rem大小
propList: ['*'], // 需要转换的属性,这里选择全部都进行转换
})
]
}
}
})
3、main.ts导入
import 'amfe-flexible'
安装后效果
比如设计稿为750px ,在iphone6/7/8中显示的宽度为750/75,也就是10rem,此时的font-size应该为37.5px
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)