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

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

javascript 复制代码
//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

相关推荐
其实防守也摸鱼34 分钟前
Day 3 · Agent Loop:从调用模型到控制循环 —— 课件精讲笔记
服务器·开发语言·javascript·数据库·人工智能·笔记·ecmascript
夕水1 小时前
我把颜色选择器拆成了 15 个插件,最后长成了 22 个包
前端·javascript·typescript
大今野1 小时前
2026 专转本计算机|移动互联网关键技术:SOA、Web2.0 与 HTML5 考点全解(附例题)
前端·html·html5·专转本
JudithHuang1 小时前
Vue3 与后端联调:代理、Mock 与接口约定
前端·vue
Swot1 小时前
工具转换 vs LLM 转换:以 Markdown 转 AsciiDoc 为例
前端
uuware2 小时前
Lupine.js 的 Native 5 端实现:一套代码覆盖 iOS、Android、macOS、Windows 和 Web
前端·typescript
用户88956195481712 小时前
戴上眼镜就把今天听完:绿光快报的 AIUI 语音新闻智能体
javascript
lisw052 小时前
前端:概念、历史、内容、挑战与展望!
前端
stormsha2 小时前
ResizeObserver loop completed with undelivered notifications:它只是个警告,但也是你代码的供词
javascript·css