当前位置:网站首页>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)
边栏推荐
- declval(指导函数返回值范例)
- 【.NET CORE】 请求长度过长报错解决方案
- C语言自动预订飞机票问题
- F200 - UAV equipped with domestic open source flight control system based on Model Design
- FMT开源自驾仪 | FMT中间件:一种高实时的分布式日志模块Mlog
- STM32+ESP8266+MQTT协议连接OneNet物联网平台
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
- 简单易用的PDF转SVG程序
- Take you through ancient Rome, the meta universe bus is coming # Invisible Cities
- Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
猜你喜欢

Maixll dock camera usage

Open source and safe "song of ice and fire"

RB157-ASEMI整流桥RB157

Kivy tutorial: support Chinese in Kivy to build cross platform applications (tutorial includes source code)

The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!

Implementation of queue
![Jerry's updated equipment resource document [chapter]](/img/6c/17bd69b34c7b1bae32604977f6bc48.jpg)
Jerry's updated equipment resource document [chapter]
![[Android] kotlin code writing standardization document](/img/d5/53d6a75e87af15799bf7e5d6eb92a5.png)
[Android] kotlin code writing standardization document

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

Maixll-Dock 摄像头使用
随机推荐
面试突击62:group by 有哪些注意事项?
30 minutes to understand PCA principal component analysis
Release of the sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
Jerry is the custom background specified by the currently used dial enable [chapter]
ASEMI整流桥DB207的导通时间与参数选择
面向程序员的精品开源字体
Heavy! Ant open source trusted privacy computing framework "argot", flexible assembly of mainstream technologies, developer friendly layered design
Grafana 9.0 正式发布!堪称最强!
Codeforces Round #803 (Div. 2)
Olivetin can safely run shell commands on Web pages (Part 1)
node の SQLite
转载:基于深度学习的工业品组件缺陷检测技术
【.NET CORE】 请求长度过长报错解决方案
IP, subnet mask, gateway, default gateway
Grafana 9.0 is officially released! It's the strongest!
MSF horizontal MSF port forwarding + routing table +socks5+proxychains
[Android] kotlin code writing standardization document
Jielizhi obtains the customized background information corresponding to the specified dial [chapter]
编译原理——预测表C语言实现
Why should Li Shufu personally take charge of building mobile phones?