当前位置:网站首页>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)
边栏推荐
猜你喜欢
QT中Model-View-Delegate委托代理机制用法介绍
Jerry's updated equipment resource document [chapter]
UDP protocol: simple because of good nature, it is inevitable to encounter "city can play"
Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
Alibaba cloud international ECS cannot log in to the pagoda panel console
Easy to use PDF to SVG program
Olivetin can safely run shell commands on Web pages (Part 1)
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
Ms-tct: INRIA & SBU proposed a multi-scale time transformer for motion detection. The effect is SOTA! Open source! (CVPR2022)...
随机推荐
STM32+ESP8266+MQTT协议连接OneNet物联网平台
Jerry is the custom background specified by the currently used dial enable [chapter]
使用block实现两个页面之间的传统价值观
容器里用systemctl运行服务报错:Failed to get D-Bus connection: Operation not permitted(解决方法)
AFNetworking框架_上传文件或图像server
2019 Alibaba cluster dataset Usage Summary
图片缩放中心
SAP Fiori 应用索引大全工具和 SAP Fiori Tools 的使用介绍
QT中Model-View-Delegate委托代理机制用法介绍
华为0基金会——图片整理
The third season of Baidu online AI competition is coming in midsummer, looking for you who love AI!
Coco2017 dataset usage (brief introduction)
Top command details
declval(指导函数返回值范例)
Redis的五种数据结构
Jerry's watch reads the file through the file name [chapter]
F200 - UAV equipped with domestic open source flight control system based on Model Design
Jerry's updated equipment resource document [chapter]
Brief description of SQL optimization problems
简单易用的PDF转SVG程序