在vue项目中,在App.vue页面,初始化就加载autofit.js,如下配置(注:还没有安装的小伙伴,请先安装 autofit.js,安装 npm install autofit.js)
autofit.js 配置(注:el 一定要写成 ‘#app’)
initAutofit() {
const options = {
el: '#app',
wh: this.screenWidth, // Width of your design layout
eh: this.screenHeight, // Height of your design layout
scaleType: 'contain', // Scaling type, 'contain' scales the content proportionally
offsetLeft: 0, // No left offset
offsetTop: 0, // No top offset
autoCenter: true, // Center the layout automatically
resize: true, // Resize elements dynamically
callback: () => {
console.log('Autofit complete');
}
};
autofit.init(options);
},
涉及到el-dialog弹出框界面,有下拉空间的,可以使用它自带的属性 :append-to-body="false" 这样设置即可。