Vue3 + vant + Echarts Tab切换不展示第二个tab页图表

15 篇文章 0 订阅
// 要写@click事件,不能写@click-tab

<van-tabs v-model:active="active" type="card" @click="changeAmount">
        <van-tab title="违规金额" lazy-render="true">
          <div id="main3" v-if="isShowLeftDom"></div>
          <no-data v-if="!dataTop10.data || !dataTop10.data.length"></no-data>
          <div v-else class="table-easy-box">
            <div class="h-tbale-container illegal-box">
              <div class="h-tbale-content">
                <table class="Htable">
                  <tr class="lastWidth">
                    <th class="h-table-cell">
                      <span>XXX</span>
                    </th>
                    <th class="h-table-cell">
                      <span>YYY</span>
                    </th>
                  </tr>
                  <tbody>
                    <tr class>
                      <td class="h-table-cell">
                        <span>会员管理</span>
                      </td>
                      <td class="h-table-cell">5%</td>
                    </tr>
                    <tr class>
                      <td class="h-table-cell">
                        <span>人事文化建设</span>
                      </td>
                      <td class="h-table-cell">6%</td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </van-tab>
        <van-tab title="营业金额" lazy-render="true">
          <div id="main4" v-if="isShowRightDom"></div>
          <no-data v-if="!dataTop10.data || !dataTop10.data.length"></no-data>
          <div v-else class="table-easy-box">
            <div class="h-tbale-container illegal-box">
              <div class="h-tbale-content">
                <table class="Htable">
                  <tr class="lastWidth">
                    <th class="h-table-cell">
                      <span>XXX</span>
                    </th>
                    <th class="h-table-cell">
                      <span>YYY</span>
                    </th>
                  </tr>
                  <tbody>
                    <tr class>
                      <td class="h-table-cell">
                        <span>会员管理</span>
                      </td>
                      <td class="h-table-cell">5%</td>
                    </tr>
                    <tr class>
                      <td class="h-table-cell">
                        <span>人事文化建设</span>
                      </td>
                      <td class="h-table-cell">6%</td>
                    </tr>
                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </van-tab>
      </van-tabs>



// 第二个Tab图表要用nextTick刷新

const illegalRightFunction = () => {
  option3 = {
    backgroundColor: "#FFF",
    grid: {
      left: "0",
      right: "0",
      bottom: "10",
      top: "20",
      containLabel: true
    },
    xAxis: {
      show: true,
      data: ["2018", "2019", "2020"],
      axisLine: {
        show: true, //隐藏X轴轴线
        lineStyle: {
          color: "#E0E0E0",
          width: 1
        }
      },
      axisTick: {
        show: false //隐藏X轴刻度
      },
      axisLabel: {
        show: true,
        interval: 0
      }
    },
    yAxis: [
      {
        type: "value",
        nameTextStyle: {
          color: "#999",
          fontSize: 10
        },

        splitLine: {
          show: true,
          lineStyle: {
            color: "#E0E0E0",
            width: 1
          }
        },
        axisTick: {
          show: false
        },
        axisLine: {
          show: false,
          lineStyle: {
            color: "#999",
            width: 1
          }
        }
      }
    ],
    dataZoom: [
      {
        type: "slider",
        show: true,
        xAxisIndex: [0],
        start: 1,
        end: 50,
        zoomLock: true, //锁定区域禁止缩放(鼠标滚动会缩放,所以禁止)
        handleSize: 0, //滑动条的 左右2个滑动条的大小
        height: 6, //组件高度
        right: 3, //右边的距离
        bottom: 0, //右边的距离
        brushSelect: false, //刷选功能
        fillerColor: "#E0E0E0", //选中范围的填充颜色
        borderColor: "#E0E0E0", //边框颜色
        backgroundColor: "#FFF", //两边未选中的滑动条区域的颜色
        borderRadius: 3,
        showDataShadow: false, //是否显示数据阴影 默认auto
        showDetail: false, //即拖拽时候是否显示详细数值信息 默认true
        filterMode: "filter"
      },
      {
        type: "inside",
        xAxisIndex: [0],
        start: 1,
        end: 50,
        zoomLock: true //锁定区域禁止缩放(鼠标滚动会缩放,所以禁止)
      }
    ],
    series: [
      {
        name: "P2",
        type: "bar",
        barWidth: 16,
        barCategoryGap: 20,
        barMinHeight: 5,
        itemStyle: {
          color: "#F4DA6C"
        },
        label: {
          show: false,
          position: "top",
          color: "#333",
          fontSize: 10
        },
        data: [10, 6, 5]
      },
      {
        name: "P3",
        type: "bar",
        barWidth: 16,
        barCategoryGap: 20,
        barMinHeight: 5,
        itemStyle: {
          color: "#D66474"
        },
        label: {
          show: false,
          position: "top",
          color: "#333",
          fontSize: 10
        },
        data: [35, 20, 55]
      }
    ]
  };

  nextTick(() => {
    var chartRighrDom = document.getElementById("main4") as HTMLElement;
    var myChart = echarts.init(chartRighrDom);
    option3 && myChart.setOption(option3);
  })

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值