1 项目使用vue完成 此次的预编译器我使用的是scss
2 因为最近时间比较充足就打算写一写这个 也利于提升自己
3 开篇先从换肤功能开始 这个也是第一次做换肤功能的 所以 对于项目中有遇到或者正好私下想学的朋友 或许有帮助
4 换肤其实和国际化差不多 都是要将颜色提取成一个变量
项目搭建
- 直接vuecli脚手架搭建即可 vue create wyymusic
1配置index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>网抑云音乐</title>
<meta name="keywords"
content="网易云音乐,音乐,播放器,网易,下载,播放,DJ,免费,明星,精选,歌单,识别音乐,收藏,分享音乐,音乐互动,高音质,320K,音乐社交,官网,移动站,music.163.com">
<meta name="description" content="网易云音乐是一款专注于发现与分享的音乐产品,依托专业音乐人、DJ、好友推荐及社交功能,为用户打造全新的音乐生活。">
<link rel="apple-touch-icon" href="./apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="114x114" href="./apple-touch-icon114.png">
<link rel="apple-touch-icon" sizes="152x152" href="./apple-touch-icon152.png">
<link rel="apple-touch-icon" sizes="180x180" href="./apple-touch-icon180.png">
<link rel="icon" href="./favicon.ico">
<script>
let scale = 1.0 / window.devicePixelRatio;
let text =
`<meta name="viewport" content="width=device-width, initial-scale=${scale}, maximum-scale=${scale}, minimum-scale=${scale}, user-scalable=no">`;
document.write(text);
document.documentElement.style.fontSize = window.innerWidth / 7.5 + "px";
document.documentElement.setAttribute('data-dpr', window.devicePixelRatio + '');
document.documentElement.setAttribute('data-theme', 'theme');
</script>
</head>
<body>
<div id="app"></div>
</body>
</html>
2 运行报错 安装 html-loader
- 注意这html-loader直接安装之后会出现一个 this.getOptions is not a function错误
- 我原本以为是less过高 特意降级成5.0 并没有解决这个问题
- 出现这个问题的原因实际上是:html-loader 的版本过高,不兼容 getOptions 方法,所以需要对 html-loader 进行降级处理;
- npm install html-loader@0.5.5 --save-dev
3 配置vue.config.js
module.exports = {
configureWebpack: {
module: {
rules: [
{
test: /\.(html)$/,
exclude: /node_modules/,
use: {
loader: "html-loader",
options: {
minimize: true
}
}
}
]
}
}
};
4 添加postcss-pxtorem插件 用来将px转成rem 或者使用flexib.js也可以
npm i -D postcss-pxtorem
5 .browserslistrc文件修改浏览器的兼容
ie >= 8
Firefox >= 3.5
chrome >= 35
opera >= 11.5
6 借助fastclick解决移动端100~300ms的点击事件延迟问题
npm i fastclick
7 在main.js中配置这个fastclick
import fastclick from 'fastclick'
fastclick.attach(document.body)
这就是搭建了一个常见的h5的一些配置 下篇开始换肤之旅