当前位置:网站首页>Echart simple component packaging
Echart simple component packaging
2022-07-06 18:20:00 【Bug pill】
echart Simple component encapsulation
<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>
Problems encountered :
Packaged echart When components are reused , Warning :
The above code if I will this.$ref Change it to document.querySelector; Then the browser will issue a warning , And only one picture will be rendered
Warning content : There is a chart instance already initialized on the dom.
// const dom = this.$refs.echartBox
const dom = document.querySelector('.chartBox')
Solution :
The way 1:this.$refs
Like the code at the beginning
The way 2: Pass in a unique className or id, Used to distinguish
<div class="chartBox" :id="eID"></div>
props: {
eID: {
type: String,
default: ''
}
},
const dom = document.querySelector('#' + this.eID)
边栏推荐
- STM32+ESP8266+MQTT协议连接OneNet物联网平台
- STM32+MFRC522完成IC卡号读取、密码修改、数据读写
- declval(指导函数返回值范例)
- [sword finger offer] 60 Points of N dice
- Today in history: the mother of Google was born; Two Turing Award pioneers born on the same day
- Rb157-asemi rectifier bridge RB157
- 图片缩放中心
- AFNetworking框架_上传文件或图像server
- C language exchanges two numbers through pointers
- Jielizhi obtains the customized background information corresponding to the specified dial [chapter]
猜你喜欢
[.Net core] solution to error reporting due to too long request length
win10系统下插入U盘有声音提示却不显示盘符
Implementation of queue
Distiller les connaissances du modèle interactif! L'Université de technologie de Chine & meituan propose Virt, qui a à la fois l'efficacité du modèle à deux tours et la performance du modèle interacti
FMT open source self driving instrument | FMT middleware: a high real-time distributed log module Mlog
2019 Alibaba cluster dataset Usage Summary
Alibaba cloud international ECS cannot log in to the pagoda panel console
30 分钟看懂 PCA 主成分分析
Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
随机推荐
传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复
Jerry's watch reading setting status [chapter]
Principle and usage of extern
Implementation of queue
從交互模型中蒸餾知識!中科大&美團提出VIRT,兼具雙塔模型的效率和交互模型的性能,在文本匹配上實現性能和效率的平衡!...
Compilation principle - top-down analysis and recursive descent analysis construction (notes)
模板于泛型编程之declval
J'aimerais dire quelques mots de plus sur ce problème de communication...
D binding function
Coco2017 dataset usage (brief introduction)
使用block实现两个页面之间的传统价值观
关于这次通信故障,我想多说几句…
Recommend easy-to-use backstage management scaffolding, everyone open source
Grafana 9.0 is officially released! It's the strongest!
std::true_type和std::false_type
Jerry's watch reads the file through the file name [chapter]
Maixll dock camera usage
[sword finger offer] 60 Points of N dice
Windows连接Linux上安装的Redis
Why does wechat use SQLite to save chat records?