当前位置:网站首页>echart简单组件封装
echart简单组件封装
2022-07-06 10:24:00 【bug丸】
echart简单组件封装
<template>
<div class="chartBox" ref="echartBox"></div>
</template>
<script>
import * as echarts from 'echarts'
export default {
props: {
barData: {
type: Array,
default: () => []
}
},
watch: {
barData: {
handler: function() {
this.initChart()
},
deep: true
}
},
mounted() {
this.initChart()
},
methods: {
initChart() {
const dom = this.$refs.echartBox
const myChart = echarts.init(dom)
myChart.setOption({
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
data: this.barData,
type: 'bar'
}
]
})
}
}
}
</script>
<style scoped>
.chartBox {
width: 400px;
height: 300px;
}
</style>
遇到的问题:
封装的echart组件复用时,会警告:
上述代码如果我将this.$ref 改为 document.querySelector;那么浏览器会出来一条警告,而且只会渲染出一个图
警告内容: There is a chart instance already initialized on the dom.
// const dom = this.$refs.echartBox
const dom = document.querySelector('.chartBox')
解决方式:
方式1:this.$refs
如同开始部分的代码
方式2:传入一个唯一的className或id,用来区分
<div class="chartBox" :id="eID"></div>
props: {
eID: {
type: String,
default: ''
}
},
const dom = document.querySelector('#' + this.eID)
边栏推荐
- 第三季百度网盘AI大赛盛夏来袭,寻找热爱AI的你!
- This article discusses the memory layout of objects in the JVM, as well as the principle and application of memory alignment and compression pointer
- Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
- 华为0基金会——图片整理
- declval(指导函数返回值范例)
- FMT开源自驾仪 | FMT中间件:一种高实时的分布式日志模块Mlog
- 78 year old professor Huake has been chasing dreams for 40 years, and the domestic database reaches dreams to sprint for IPO
- 2019 Alibaba cluster dataset Usage Summary
- MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...
- Maixll dock camera usage
猜你喜欢
![[Android] kotlin code writing standardization document](/img/d5/53d6a75e87af15799bf7e5d6eb92a5.png)
[Android] kotlin code writing standardization document

Easy to use PDF to SVG program

Introduction to the usage of model view delegate principal-agent mechanism in QT

Virtual machine VirtualBox and vagrant installation

QT中Model-View-Delegate委托代理机制用法介绍

Compilation principle - top-down analysis and recursive descent analysis construction (notes)

编译原理——自上而下分析与递归下降分析构造(笔记)

【Swoole系列2.1】先把Swoole跑起来

【.NET CORE】 请求长度过长报错解决方案

Prophet模型的简介以及案例分析
随机推荐
Jerry's updated equipment resource document [chapter]
CRMEB 商城系统如何助力营销?
D binding function
Kill -9 system call used by PID to kill process
转载:基于深度学习的工业品组件缺陷检测技术
Fleet tutorial 13 basic introduction to listview's most commonly used scroll controls (tutorial includes source code)
High precision operation
node の SQLite
Maixll dock camera usage
Running the service with systemctl in the container reports an error: failed to get D-Bus connection: operation not permitted (solution)
Jerry's watch reads the file through the file name [chapter]
【.NET CORE】 请求长度过长报错解决方案
Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...
Maixll-Dock 摄像头使用
Jielizhi obtains the customized background information corresponding to the specified dial [chapter]
Why does wechat use SQLite to save chat records?
Jielizhi obtains the currently used dial information [chapter]
传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复
带你穿越古罗马,元宇宙巴士来啦 #Invisible Cities
RB157-ASEMI整流桥RB157