APP移动端不同屏幕手机之间兼容问题

APP移动端不同屏幕手机之间兼容问题

前提介绍rem.js(vant-ui)

//============rem.js
const baseSize = 75
// 设置 rem 函数
function setRem() {
    // 当前页面宽度相对于 750 宽的缩放比例,可根据自己需要修改。
    const scale = document.documentElement.clientWidth / 750
    // 设置页面根节点字体大小(在750的设计稿中量多少px,就在页面css中写多少px,750的时候,为37.5px)
    document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + 'px'
}
// 初始化
setRem()
// 改变窗口大小时重新设置 rem
window.onresize = function() {
    setRem()
}

想实现的效果

超过三行隐藏下面的
在这里插入图片描述

主要的代码

 <div class="manage-wrap">
       <div class="manage-title-wrap">
               经营范围:
        </div>
        <div class="textOver" ref="range">
               {{ this.companylist.businessItems }}
        </div>
           <span class="open" v-if="openFlag" @click="openClick">
               展开全部
               <van-icon name="arrow-down" />
           </span>
           <span class="close" v-if="closeFlag" @click="closeClick">
                收起
               <van-icon name="arrow-up" />
           </span>
  </div>

 data() {
        return {
            openFlag: false,
            closeFlag: false,
        }
    },
  //生命周期 created(请求)----mounted(获取不到请求的数据)----updated(异步数据请求过来了,更新视图)
   watch: {
        companylist: function() {
            this.$nextTick(() => {
                var h = this.$refs.range.offsetHeight //父未设置高度,自动撑开的高度
                var t = 75 * Math.min(document.documentElement.clientWidth / 750, 2)
                // if (h > 45) {  //
                if (h > t * 0.4 * 3) {   //我设置的行高是30px,转换成是0.4rem
                    // 兼容三倍屏幕手机
                    this.$refs.range.setAttribute('class', 'textOVerThree')
                    this.openFlag = true
                    this.closeFlag = false
                } else {
                    this.openFlag = false
                    this.closeFlag = false
                }
            })
        },
    },
  methods: {
        openClick() {
            this.$refs.range.removeAttribute('class')
            this.openFlag = false
            this.closeFlag = true
        },
        closeClick() {
            this.$refs.range.setAttribute('class', 'textOVerThree')
            this.openFlag = true
            this.closeFlag = false
        },
    }

链接: https://blog.csdn.net/weixin_39682560/article/details/111271384.下载个插件
链接: https://blog.csdn.net/qq_43999459/article/details/109693659.获取不到offsetHeight
链接: https://blog.csdn.net/cha1919/article/details/107631856.
链接: https://blog.csdn.net/zhuyuchen321/article/details/81941190?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值