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

相关推荐
遇到困难睡大觉哈哈5 小时前
Harmony os 静态卡片(ArkTS + FormLink)详细介绍
前端·microsoft·harmonyos·鸿蒙
用户47949283569155 小时前
Bun 卖身 Anthropic!尤雨溪神吐槽:OpenAI 你需要工具链吗?
前端·openai·bun
p***43485 小时前
前端在移动端中的网络请求优化
前端
g***B7385 小时前
前端在移动端中的Ionic
前端
大猩猩X6 小时前
vxe-gantt 甘特图使用右键菜单
vue.js·vxe-table·vxe-ui·vxe-gantt
拿破轮6 小时前
使用通义灵码解决复杂正则表达式替换字符串的问题.
java·服务器·前端
whltaoin6 小时前
【 Web认证 】Cookie、Session 与 JWT Token:Web 认证机制的原理、实现与对比
前端·web·jwt·cookie·session·认证机制
Aerelin6 小时前
爬虫playwright入门讲解
前端·javascript·html·playwright
笙年7 小时前
JavaScript Promise,包括构造函数、对象方法和类方法
开发语言·javascript·ecmascript
桜吹雪7 小时前
LangChain.js/DeepAgents可观测性
javascript·人工智能