在使用v-show的来切换两个独立的echarts的时候会出现显示不全的问题,也就是宽度只有100px

<template>
  <div id="app">
  <div v-show="fl" id="myChart" :style="{width: '100%', height: '300px'}"></div>
  <div v-show="!fl" id="myChart2" :style="{width: '100%', height: '300px'}"></div>

    <button @click="change">切换</button>

  </div>
</template>
<script>
let myChart
let myChart2
export default {
  components: {
  },
  computed:{

  },

  data () {
    return {
      fl:true
    }
  },
  created () {
  },
  mounted () {
    this.drawLine()
     this.drawLine2()

  },
  watch:{
    // fl(newv,oldv){
    //   if(newv){
    //     console.log(myChart.resize);
    //       this.$nextTick(()=>{
    //          myChart.resize()
    //       })
    //   }
    //   else{
    //     console.log(myChart2);
    //           this.$nextTick(()=>{
    //          myChart2.resize()
    //       })
    //   }
    // }
  },

  methods: {
    change(){
      this.fl = !this.fl
    },
        drawLine(){
        // 基于准备好的dom,初始化echarts实例
         myChart = this.$echarts.init(document.getElementById('myChart'))
        // 绘制图表
         myChart.setOption({
            title: { text: '在Vue中使用echarts' },
            tooltip: {},
            xAxis: {
                data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 90]
            }]
        });
          window.addEventListener('resize',  window.addEventListener('resize',()=>{
              myChart.resize()
            }))
        },
        drawLine2(){
        // 基于准备好的dom,初始化echarts实例
         myChart2 = this.$echarts.init(document.getElementById('myChart2'))
        // 绘制图表
        myChart2.setOption({
            title: { text: '在Vue中使用echarts' },
            tooltip: {},
            xAxis: {
                data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        });


            window.addEventListener('resize',()=>{
              myChart2.resize()
            })
        }
  }
}
</script>
<style lang="less">
#dv-full-screen-container{
  background-color: #282c34;
  color: white;
}
/deep/ .el-select-dropdown{
  max-height: 100px!important;
}

</style>

在这里插入图片描述
在这里插入图片描述
解决犯法
在这里插入图片描述
也就是我代码中注释的部分。
需要你手动调用改图表的resize方法

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值