VUE项目底部tab切换如何解决在iPhoneX和iPhoneX Max 的底部小黑条挡住的问题

最近在移动端项目上遇到了底部tab切换被iPhoneX 和 iPhoneX Max 的小黑条影响到的问题,经过多次调试,最终的解决方案如下:

1.  新增 viweport-fit 属性,使得页面内容完全覆盖整个窗口

(千万不要忘了,不然后面样式都没效果)

<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width,viewport-fit=cover">

2.页面主体内容限定在安全区域内

body {
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
}

3.fixed 元素的适配

/*iphoneX*/
@media only screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
    .van-tabbar--fixed{
          padding-bottom: 10px !important;
          padding-bottom: constant(safe-area-inset-bottom);
          padding-bottom: env(safe-area-inset-bottom);
      }
}
/*iphoneX Max*/
@media only screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) {
    .van-tabbar--fixed{
          padding-bottom: 10px !important;
          padding-bottom: constant(safe-area-inset-bottom);
          padding-bottom: env(safe-area-inset-bottom);
      }
}

以上就解决了

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果在 Vue 中使用 tab 切换解决 ECharts 图表宽度只有 100px 的问题,你可以在 tab 切换的回调函数中重新渲染 ECharts 图表,并设置正确的宽度。 首先,在 Vue 组件中引入 ECharts 和 tab 组件,然后在模板中设置一个包含 tab 切换的容器和一个用于显示 ECharts 图表的容器,例如: ```html <template> <div> <div class="tabs"> <button @click="changeTab('tab1')">Tab 1</button> <button @click="changeTab('tab2')">Tab 2</button> <button @click="changeTab('tab3')">Tab 3</button> </div> <div class="chart-container"> <div v-if="currentTab === 'tab1'" ref="chart1"></div> <div v-if="currentTab === 'tab2'" ref="chart2"></div> <div v-if="currentTab === 'tab3'" ref="chart3"></div> </div> </div> </template> ``` 接下来,在 Vue 组件的 JavaScript 部分,你可以使用 ECharts 的实例对象进行图表的初始化和渲染。在 tab 切换的回调函数中,你可以重新渲染图表,并设置正确的宽度。例如: ```javascript <script> import echarts from 'echarts'; export default { data() { return { currentTab: 'tab1', chart1: null, chart2: null, chart3: null }; }, mounted() { this.chart1 = echarts.init(this.$refs.chart1); this.chart2 = echarts.init(this.$refs.chart2); this.chart3 = echarts.init(this.$refs.chart3); // 初始化图表配置... // this.chart1.setOption({...}); // this.chart2.setOption({...}); // this.chart3.setOption({...}); }, methods: { changeTab(tab) { this.currentTab = tab; // 在切换 tab 时重新渲染图表,并设置宽度 if (tab === 'tab1') { this.chart1.resize(); } else if (tab === 'tab2') { this.chart2.resize(); } else if (tab === 'tab3') { this.chart3.resize(); } } } }; </script> ``` 通过使用 ref 属性和 ECharts 的 resize() 方法,你可以在切换 tab 时重新渲染图表并调整宽度。确保在 mounted 钩子函数中初始化图表实例,并在切换 tab 时调用对应图表的 resize() 方法。 这样,每次切换 tab 时,ECharts 图表都会重新渲染,并且会根据容器的宽度自动调整图表的宽度。 希望这能解决你的问题!如果还有其他疑问,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值