Vue适配移动端,动态计算rem

https://www.jianshu.com/p/3163bc9f7e47

//引入rem.js,在assets中创建rem文件夹引入:

import rem from './assets/rem/rem'

或者直接在 index.html 下面加 里(我就不引入了)

(function (doc, win) {
  	var docEl = doc.documentElement,
    resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
    recalc = function () {
		var clientWidth = docEl.clientWidth;
		if (!clientWidth) return;
		docEl.style.fontSize = 50 * (clientWidth / 375) + 'px';
		console.log(docEl.style.fontSize)
    };
	if (!doc.addEventListener) return;
	win.addEventListener(resizeEvt, recalc, false);
	doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);

 

你可能感兴趣的:(Vue.js)