vue2+echarts:echarts在dialog弹框中不显示的解决方案

重点是@open方法里使用$nextTick拿到最新的dom,在里面加载echarts 

//html
<el-button @click.stop="getIfStorage"></el-button>

<el-dialog title="图表数据" :visible.sync="ifStorageShowOpen" @open="open()" width="1400px" append-to-body>
  <div id="chart" style="height: 600px" ref="chart"></div>
</el-dialog>


//data
 ifStorageShowOpen: false,
 chart: null,// echarts图表实例


//js
 getIfStorage () {
    this.ifStorageShowOpen = true
 },
 open () {
    this.$nextTick(() => {
      this.initChart();
    })
 },
  // 初始化echarts
 initChart () {
    this.chart = this.$echarts.init(this.$refs.chart)
      // 设置图表option(配置项)绘制图表
      // 绘制图表
      this.chart.setOption({
        title: {
          text: '商品销售数据'
        },
        tooltip: {},
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {
          type: 'value'
        },
        backgroundColor: '#dddddd',
        color: ['#72ccff', '#d4a4eb'],
        series: [
          {
            name: '销量',
            type: 'bar', // 柱状图
            data: [5, 20, 36, 10, 10, 20]
          },
          {
            name: '利润',
            smooth: true,
            type: 'line', // 折线图
            data: [2, 23, 5, 54, 9, 33]
          }
        ]
      })
  },

 


 上一篇文章,

uniapp踩坑之项目:uni-app实现下拉框多选_uniapp 多选-CSDN博客文章浏览阅读881次,点赞5次,收藏5次。uniapp踩坑之项目:uni-app实现下拉框多选。一、首先创建组件,二、将组件引入单页面使用_uniapp 多选https://blog.csdn.net/weixin_43928112/article/details/138559471?spm=1001.2014.3001.5501

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-16 23:28:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-16 23:28:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-16 23:28:04       82 阅读
  4. Python语言-面向对象

    2024-06-16 23:28:04       91 阅读

热门阅读

  1. Oracle 19C 数据库表被误删除的模拟恢复

    2024-06-16 23:28:04       24 阅读
  2. Ubuntu20.04 使用scrapy-splash爬取动态网页

    2024-06-16 23:28:04       31 阅读
  3. C++基础之红黑树

    2024-06-16 23:28:04       31 阅读
  4. jQuery中.text() 和 .val()辨析

    2024-06-16 23:28:04       26 阅读
  5. GitHub项目的core文件夹

    2024-06-16 23:28:04       28 阅读
  6. 指定GPU跑模型

    2024-06-16 23:28:04       34 阅读
  7. 分库分表实践:单 KEY 业务场景

    2024-06-16 23:28:04       33 阅读
  8. MySQL分组聚合

    2024-06-16 23:28:04       31 阅读
  9. Redis缓存穿透、缓存雪崩和缓存击穿的解决方案

    2024-06-16 23:28:04       32 阅读
  10. 计算机行业

    2024-06-16 23:28:04       19 阅读
  11. 002 IOC和DI使用

    2024-06-16 23:28:04       28 阅读
  12. Python中*args 和**kwargs的用法

    2024-06-16 23:28:04       25 阅读
  13. os实训课程模拟考试(1~7)

    2024-06-16 23:28:04       22 阅读