uniapp改变设置改变全局字体大小功能

做一个能够控制app全部页面字体大小的功能类似于微信设置中的,调节字体大小功能PlanA:(在百度上查到的)通过在页面设置page-meta,设置根节点大小,来控制页面元素rem单位的大小https://uniapp.dcloud.io/component/page-meta?id=page-meta具体步骤:
1.创建一个公共的sizeUtil.js文件

export default {
    
    
    created() {
    
    
        const self = this;

    },
    mounted() {
    
    
        const self = this;
    },
    methods: {
    
    
        //设置字体
        getRootFontSize(){
    
    
            const self = this;
            var fontSize = getApp().globalData.rootFontSize;
            if(fontSize){
    
    
                return fontSize;
            }else{
    
    
                fontSize = uni.getStorageSync('root_font_size');
                if(fontSize){
    
    
                    getApp().globalData.rootFontSize=fontSize;
                }else{
    
    
                    fontSize='1px';//默认字体大小
                    self.setRootFontSize(fontSize);
                }
                return fontSize;
            }
        },
        setRootFontSize(fontSize){
    
    
            uni.setStorageSync('root_font_size',fontSize);
            getApp().globalData.rootFontSize=fontSize;
        },

    }
}

在这里插入图片描述

2.引用
在页面头加入page-meta

  <page-meta :root-font-size="getRootFontSize()"></page-meta>

在这里插入图片描述

export default {
    
    
     extends: sizeUtil,

在这里插入图片描述
3.使用

 .login-content {
    
    
        position: fixed;
        top: calc(15% - 0rem);
        width: calc(100% - 0rem);

猜你喜欢

转载自blog.csdn.net/qq_36158551/article/details/128507440