Skip to content

Commit 21e570b

Browse files
committed
px to vw 设置(不同手机宽度自适应)
1 parent b27b9ea commit 21e570b

File tree

7 files changed

+1497
-269
lines changed

7 files changed

+1497
-269
lines changed

package-lock.json

Lines changed: 1455 additions & 264 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@
1010
"dependencies": {
1111
"axios": "^0.20.0",
1212
"core-js": "^3.6.5",
13+
"cssnano": "^4.1.10",
14+
"cssnano-preset-advanced": "^4.0.7",
1315
"date-fns": "^2.16.1",
1416
"lodash": "^4.17.20",
17+
"postcss-aspect-ratio-mini": "^1.1.0",
18+
"postcss-cssnext": "^3.1.0",
19+
"postcss-px-to-viewport": "^1.1.1",
20+
"postcss-viewport-units": "^0.1.6",
21+
"postcss-write-svg": "^3.0.1",
1522
"svg-sprite-loader": "^5.0.0",
1623
"vant": "^2.12.3",
1724
"vue": "^2.6.11",

public/index.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover"/>
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, viewport-fit=cover"/>
77
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
88
<title>员工关怀</title>
9+
<script src="//g.alicdn.com/fdilab/lib3rd/viewport-units-buggyfill/0.6.2/??viewport-units-buggyfill.hacks.min.js,viewport-units-buggyfill.min.js"></script>
910
</head>
1011
<body>
1112
<noscript>
@@ -14,4 +15,10 @@
1415
<div id="app"></div>
1516
<!-- built files will be auto injected -->
1617
</body>
18+
<script>
19+
// vw兼容性处理viewport-units-buggyfill
20+
window.onload = function () {
21+
window.viewportUnitsBuggyfill.init({ hacks: window.viewportUnitsBuggyfillHacks });
22+
}
23+
</script>
1724
</html>

src/components/footer/footer.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default {
5050
flex: 1;
5151
height: 100%;
5252
line-height: 50px;
53-
font-size: 18px;
53+
font-size: 16px;
5454
text-align: center;
5555
color: rgba(0, 0, 0, 0.85);
5656

src/styles/index.less

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ a {
1717
text-decoration: none
1818
}
1919

20+
img {
21+
content: normal !important;
22+
}
23+
2024
.default-btn{
2125
color: white;
2226
background: linear-gradient(to right, #32ADD6, #21DE9C);
@@ -31,12 +35,12 @@ a {
3135
}
3236

3337
.style-title{
34-
font-size: 18px;
38+
font-size: 16px;
3539
color: rgba(0, 0, 0, 0.85);
3640
font-weight: bold;
3741
}
3842

3943
.style-sub-title{
40-
font-size: 13px;
44+
font-size: 12px;
4145
color: rgba(0, 0, 0, 0.65);
4246
}

src/views/layout/layout.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ export default {
112112
.home-header {
113113
background: linear-gradient(to right, #32add6, #21de9c);
114114
::v-deep {
115-
.van-nav-bar__content {
115+
.van-nav-bar {
116116
background: linear-gradient(to right, #32add6, #21de9c);
117117
}
118+
118119
.van-icon {
119120
color: white;
120121
font-size: 20px;

vue.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
const path = require("path");
3+
const pxtovw = require("postcss-px-to-viewport");
34

45
function resolve(dir) {
56
return path.join(__dirname, dir);
@@ -62,6 +63,23 @@ module.exports = {
6263
hack: `true; @import "styles/vant-theme.less";`
6364
}
6465
}
66+
},
67+
postcss: {
68+
plugins: [
69+
new pxtovw({
70+
unitToConvert: "px", //需要转换的单位,默认为"px";
71+
viewportWidth: 375, //设计稿的视口宽度(vant是375)
72+
unitPrecision: 5, //单位转换后保留的小数位数
73+
propList: ["*"], //要进行转换的属性列表,*表示匹配所有,!表示不转换
74+
viewportUnit: "vw", //转换后的视口单位
75+
fontViewportUnit: "vw", //转换后字体使用的视口单位
76+
selectorBlackList: [".ignore", ".hairlines"], //不进行转换的css选择器,继续使用原有单位
77+
minPixelValue: 1, //设置最小的转换数值
78+
mediaQuery: false, //设置媒体查询里的单位是否需要转换单位
79+
replace: true, //是否直接更换属性值,而不添加备用属性
80+
// exclude: [/node_modules/] //忽略某些文件夹下的文件
81+
})
82+
]
6583
}
6684
}
6785
}

0 commit comments

Comments
 (0)