1. 程式人生 > >vue 響應式rem css編寫

vue 響應式rem css編寫

第一步:封裝設定rem的方法,放在公用類的js檔案中,或者直接放在main.js檔案中。 export function getRem (pwidth, prem) {   var html = document.getElementsByTagName('html')[0]   var oWidth = document.body.clientWidth || document.documentElement.clientWidth   html.style.fontSize = oWidth / pwidth * prem + 'px' } 第二步:main.js 中設定公用方法。  

Vue.prototype.getRem = getRem 第三步: 元件mounted中使用getRem方法(注意此方法放在mounted中所有操作的最後)。

mounted  () {   this.getRem(750, 100) }   原文:https://blog.csdn.net/Stiven_Lu/article/details/80451073