编程知识 cdmana.com

Vue project adaptive page configuration

Development projects need adaptive pages
We can create... In the root directory utils Folder , Create in folder rem.js file

//  Set up  rem  function 
(function () {
    function setRem () {
    // 1920  Default size 16px; Every element px On the basis of /16
        const htmlWidth = document.documentElement.clientWidth || document.body.clientWidth
        document.documentElement.style.fontSize = htmlWidth * 16 / 1920 + 'px'
    }
    //  initialization 
    setRem()
    window.addEventListener('resize', setRem, false)
})()

Then introduce to main.js

import '@/utils/rem'

版权声明
本文为[Li Jiachen]所创,转载请带上原文链接,感谢

Scroll to Top