问题分析:

一般第三方ui框架用的都是不同的适配方式,如果我们使用了vw适配,那么在使用mint-ui框架时,就会发现px单位会被转换成vw,从而导致样式变小的问题,如图

解决方案

网上看到了很多种解决方案,这里推荐第四种

1、重写第三方组件ui样式大小

2、在postcss.config.js中的selectorBlackList选项中增加不需要vw转换的类名

selectorBlackList: ['.ignore', '.hairlines'], // (Array) The selectors to ignore and leave as px.

3、使用rem适配方案,将原本750的宽度设置为一半,配置成37.5

https://www.jianshu.com/p/8f9aab666c4a

4、添加exclude选项,将node_modules目录排除掉,即不会受影响

在node_mudule中找到postcss-px-to-viewport,修改index.js新增对exclude选项的处理

module.exports = postcss.plugin('postcss-px-to-viewport', function (options) {

  var opts = objectAssign({}, defaults, options);
var pxReplace = createPxReplace(opts.viewportWidth, opts.minPixelValue, opts.unitPrecision, opts.viewportUnit); return function (css) { css.walkDecls(function (decl, i) {
if (options.exclude) { // 添加对exclude选项的处理
if (Object.prototype.toString.call(options.exclude) !== '[object RegExp]') {
throw new Error('options.exclude should be RegExp!')
}
if (decl.source.input.file.match(options.exclude) !== null) return;
}
// This should be the fastest test and will remove most declarations
if (decl.value.indexOf('px') === -1) return; if (blacklistedSelector(opts.selectorBlackList, decl.parent.selector)) return; decl.value = decl.value.replace(pxRegex, pxReplace);
}); if (opts.mediaQuery) {
css.walkAtRules('media', function (rule) {
if (rule.params.indexOf('px') === -1) return;
rule.params = rule.params.replace(pxRegex, pxReplace);
});
} };
});

然后在.postcssrc.js添加postcss-px-to-viewport的exclude选项

"postcss-px-to-viewport": {
viewportWidth: 750,
viewportHeight: 1334,
unitPrecision: 3,
viewportUnit: 'vw',
selectorBlackList: ['.ignore', '.hairlines'],
minPixelValue: 1,
mediaQuery: false,
exclude: /(\/|\\)(node_modules)(\/|\\)/
},

这里需要注意了,在没有修改postcss-px-to-viewport的index.js文件,直接在.postcssrc.js中添加了以下代码也成功了

exclude: /(\/|\\)(node_modules)(\/|\\)/

然后我去node_mudele下找到postcss-px-to-viewport的index.js打开发现了如下代码,看来是postcss-px-to-viewpor这个插件增加了对这个问题的处理, 我使用的版本是"postcss-px-to-viewport": "^1.1.0",

if (opts.exclude && file) {
if (Object.prototype.toString.call(opts.exclude) === '[object RegExp]') {
if (isExclude(opts.exclude, file)) return;
} else if (Object.prototype.toString.call(opts.exclude) === '[object Array]') {
for (let i = 0; i < opts.exclude.length; i++) {
if (isExclude(opts.exclude[i], file)) return;
}
} else {
throw new Error('options.exclude should be RegExp or Array.');
}
}

参考阅读

Vue+ts下的移动端vw适配(第三方库css问题)

最新文章

  1. Creating a SharePoint Sequential Workflow
  2. 关于js css html加载顺序整理
  3. 45. Singleton类的C++/C#实现[Singleton]
  4. ulua slua 下载地址
  5. Hadoop MRUnit使用(一)
  6. Hadoop构成
  7. php发送get、post请求的几种方法
  8. Quartus II调用modelsim无缝仿真
  9. tableview: 实现tableview 的 section header 跟随tableview滑动
  10. PL/SQL编程(1) - 存储过程,函数以及参数
  11. gdb 远程调试android进程 -转
  12. Nagios状态长时间处于Pending的解决方法
  13. Java内存泄漏分析系列之四:jstack生成的Thread Dump日志线程状态
  14. 【一天一道LeetCode】#40. Combination Sum II
  15. 实现Kubernetes跨集群服务应用的高可用
  16. Tomcat架构解析(五)-----Tomcat的类加载机制
  17. 关于a标签的onclick与href的执行顺序
  18. linux 的常用命令---------第四阶段
  19. virtualBox导入虚拟机启动报错
  20. Microsoft.AspNet.Identity.EntityFramework/IdentityDbContext.cs

热门文章

  1. django之admin组件
  2. 2.2.3 Analyzing the output 分析对用户推荐书目的结果(2)
  3. [Python Study Notes]一个简单的区块链结构(python 2.7)
  4. 下载Django
  5. day36-hibernate检索和优化
  6. CentOS 7 下设置DNS
  7. go语言linux下安装
  8. koa的教程
  9. vray学习笔记(2)vray工作流程
  10. WOJ 18 动态无向图