The vue html root font changes with the browser resolution, dynamically changing the font-size of html

Dynamically change the font-size of html, px changes with the size of the browser, not much to say about the code.
1. App.vue

resizeFun() {
            let docEle = document.documentElement,
                resizeEvt =
                    'orientationchange' in window ? 'orientationchange' : 'resize',
                resizeFun = () => {
                    let clientWidth = docEle.clientWidth;
                    if (!clientWidth) return;
                    docEle.style.fontSize = 100 * (clientWidth / 1920) + 'px';
                };
            if (!document.addEventListener) return;
            window.addEventListener(resizeEvt, resizeFun, false);
            window.addEventListener('DOMContentLoaded', resizeFun, false);
            resizeFun();
        },

Guess you like

Origin blog.csdn.net/qq_41954585/article/details/129485806