vue-cli 中使用rem
一、直接引入rem.js
- 在src文件下面定义remConfig.js 文件
export default function() {
var deviceWidth = document.documentElement.clientWidth;
if(deviceWidth > 750) {
deviceWidth = 7.5 * 50;
}
document.documentElement.style.fontSize = deviceWidth / 7.5 + 'px';
// 禁止双击放大
document.documentElement.addEventListener('touchstart', function (event) {
if (event.touches.length > 1) {
event.preventDefault();
}
}, false);
var lastTouchEnd = 0;
document.documentElement.addEventListener('touchend', function (event) {
var now = Date.now();
if (now - lastTouchEnd <= 300) {
event.preventDefault();
}
lastTouchEnd = now;
}, false);
}