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 

猜你喜欢

转载自blog.csdn.net/ToBeBestPlayer/article/details/83345873