账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    React dva中使用Ant Design Mobile 开发,在项目中字体怎么设置
    34
    0

    一般手机都是设置rem为单位 。
    在使用Ant Design Mobile 开发,在项目字体要怎么设置?

    有人说在public/index.html设置如下,然后在组件用就以1rem =100px 为基准来设置。

        (function (baseFontSize, fontscale) {
            var _baseFontSize = baseFontSize || 100;
            var _fontscale = fontscale || 1;
            var win = window;
            var doc = win.document;
            var ua = navigator.userAgent;
            var matches = ua.match(/Android[\S\s]+AppleWebkit\/(\d{3})/i);
            var UCversion = ua.match(/U3\/((\d+|\.){5,})/i);
            var isUCHd = UCversion && parseInt(UCversion[1].split('.').join(''), 10) >= 80;
            var isIos = navigator.appVersion.match(/(iphone|ipad|ipod)/gi);
            var dpr = win.devicePixelRatio || 1;
            if (!isIos && !(matches && matches[1] > 534) && !isUCHd) {
                // 如果非iOS, 非Android4.3以上, 非UC内核, 就不执行高清, dpr设为1;
                dpr = 1;
            }
            var scale = 1 / dpr;
    
            var metaEl = doc.querySelector('meta[name="viewport"]');
            if (!metaEl) {
                metaEl = doc.createElement('meta');
                metaEl.setAttribute('name', 'viewport');
                doc.head.appendChild(metaEl);
            }
            metaEl.setAttribute('content', 'width=device-width,user-scalable=no,initial-scale=' + scale + ',maximum-scale=' + scale + ',minimum-scale=' + scale);
            doc.documentElement.style.fontSize = _baseFontSize / 2 * dpr * _fontscale + 'px';
            window.viewportScale = dpr;
        })();
        if(!window.Promise) {
            document.writeln('<script src="./js/es6-promise.auto.min.js"'+'>'+'<'+'/'+'script>');
        }

    请问这样合理吗?可以适配各种手机吗?

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 许我一个天亮 普通会员 1楼

      在React Dva中使用Ant Design Mobile开发,在项目中字体设置可以通过CSS来实现。

      1. 首先,你需要在你的CSS文件中引入Ant Design Mobile的CSS文件。如果你使用的是HBuilder X,可以在你的项目中引入HBuilder X的CSS文件。如果你使用的是Vue CLI,可以在你的项目中引入Vue CLI的CSS文件。

      css @import 'antd/dist/antd.css';

      1. 然后,你可以使用antd-pro来使用Ant Design Mobile的组件。如果你使用的是HBuilder X,你可以使用@import 'antd-pro/dist/antd-pro.css'来引入antd-pro的CSS文件。

      css @import 'antd-pro/dist/antd-pro.css';

      1. 在你的组件中,你可以使用<style>标签来引入你的CSS文件。如果你使用的是HBuilder X,你可以使用<style>标签来引入antd-pro的CSS文件。如果你使用的是Vue CLI,你可以使用<style>标签来引入你的CSS文件。

      ```css

      ```

      以上就是在React Dva中使用Ant Design Mobile开发,在项目中字体设置的步骤。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部