echarts不同按钮切换不同图表

父页面上有一个echarts,子页面封装了一个echarts,通过两个按钮切换不同的图表。
在网上搜了很久,也没有搜到自己想要的。不是同一个图表更换数据源,而是就是两个不同的图表切换。
遇到的问题是第一个切换到第二个的时候,第二个只有100px左右大小,或者第二个页面上半截空了一大片,下半截才是图表。
或者第二个切换回来第一个不显示或者都在第一个页面上显示。
因为一边百度一边调试,整整花了一天时间,才搞正常。
现在回过头想一想,还是自己写的不对,导致一直都不对。
在这里插入图片描述
在这里插入图片描述

父页面:

<template>
  <div class="wholeTotal">
    <div style="width:100%;height: 95%" v-if="echartsFlag == 0">
      <div id="anaysisEcharts" style="width: 100%; height: 95%"></div>
    </div>
    <div class="totalButton">
      <a-button @click="apiCountRef()" class="apiButton" :class="{ active: echartsFlag == 0 }">接口数量</a-button>
      <a-button @click="cashAmountRef()" class="apiButton" :class="{ active: echartsFlag == 1 }">金额</a-button>
    </div>
     <cash-amount-modules ref="cashAmountRef" v-if="echartsFlag == 1" />
      </div>  
      </template>

data中 echartsFlag: 0,
方法中当从第二个页面切换回第一个页面时,要刷新第一个图表相关的方法,这个比较重要!!!!

 apiCountRef() {
      this.echartsFlag = 0
      this.$nextTick(() => {
        this.initEaharts()
        this.initData()
        let that = this
        window.onresize = function() {
          that.echart.resize()
        }
      })
    },
    cashAmountRef() {
      this.echartsFlag = 1
     
    },
.wholeTotal {
  width: 100%;
  height: 100%;
  .totalButton {
    width: 240px;
    position: absolute;
    bottom: 40px;
    right: 80px;
    .apiButton {
      width: 100px;
      margin-right: 10px;
      color: #fff;
      font-size: 15px;
      font-weight: 700;
      background: #aaaaaa;
      &:hover {
        background: #4373b9;
      }
    }
  }
  .active {
    background: #4373b9 !important;
  }
}

子组件,注意子组件的根div类名一定不要和父组件的有重复的,我在这里也跌了坑,花了一个小时才发现类名重复了,导致样式显示不正常

<template>
  <!-- 金额 -->
  <div class="Cashcontent">
    <div id="cashEcharts" class="apiamount"></div>
    </div>
</template>
.Cashcontent {
  width: 100vw;
  height: calc(100vh - 35px);
  .apiamount {
    width: 100%;
    height: 95%;
  }
}
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值