安装插件
npm install postcss-pxtorem && amfe-flexible
main.ts
import 'amfe-flexible';
vite.config.ts
import postCssPxToRem from 'postcss-pxtorem';
...
css: {
postcss: {
plugins: [
postCssPxToRem({
rootValue: 192,
propList: ['*'],
}),
],
},
},
App.vue
import { BrowserSize } from '@/utils/index';
onMounted(() => {
BrowserSize();
});
export function BrowserSize() {
var docEl = document.documentElement,
clientWidth: number,
clientHeight: number,
clientWidth = docEl.clientWidth;
clientHeight = docEl.clientHeight;
if (!clientWidth) return;
if (!docEl.addEventListener) return;
docEl.style.fontSize = clientWidth / 10 + 'px';
}