UNPKG

press-ui

Version:

简单、易用的跨端组件库,兼容 Vue2 和 Vue3,同时支持 uni-app和普通 Vue 项目

46 lines (40 loc) 997 B
export const uniSystemInfoMixin = { data() { return { mixinRootFontSize: 50, }; }, computed: { }, mounted() { this.onSetFontSize(); }, beforeDestroy() { }, methods: { onSetFontSize() { // 宽度 375 时(iphone6),rootFontSize为50,则一份为 375/50=7.5 const screenNumber = 7.5; const that = this; if (that.mpType === 'page') { try { // 窗体改变大小触发事件 uni.onWindowResize((res) => { if (res?.size?.windowWidth) { that.mixinRootFontSize = parseFloat(`${res?.size?.windowWidth}`) / screenNumber; } }); // 打开获取屏幕大小 uni.getSystemInfo({ success(res) { const fontsize = res.screenWidth / screenNumber; that.mixinRootFontSize = fontsize; }, }); } catch (err) { console.log('err', err); } } }, }, };