当前位置:网站首页>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)
边栏推荐
- IP, subnet mask, gateway, default gateway
- 递归的方式
- Grafana 9.0 正式发布!堪称最强!
- 重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
- The integrated real-time HTAP database stonedb, how to replace MySQL and achieve nearly a hundredfold performance improvement
- 【LeetCode第 300 场周赛】
- Open source and safe "song of ice and fire"
- 用友OA漏洞学习——NCFindWeb 目录遍历漏洞
- 【Swoole系列2.1】先把Swoole跑起来
- win10系统下插入U盘有声音提示却不显示盘符
猜你喜欢

TOP命令详解

Open source and safe "song of ice and fire"

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

F200 - UAV equipped with domestic open source flight control system based on Model Design

Transport layer congestion control - slow start and congestion avoidance, fast retransmission, fast recovery

2019阿里集群数据集使用总结

传输层 拥塞控制-慢开始和拥塞避免 快重传 快恢复

1700C - Helping the Nature

Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)

Grafana 9.0 is officially released! It's the strongest!
随机推荐
DOM简要
Why does wechat use SQLite to save chat records?
【.NET CORE】 请求长度过长报错解决方案
转载:基于深度学习的工业品组件缺陷检测技术
Compilation principle - top-down analysis and recursive descent analysis construction (notes)
Windows连接Linux上安装的Redis
Release of the sample chapter of "uncover the secrets of asp.net core 6 framework" [200 pages /5 chapters]
Five data structures of redis
Heavy! Ant open source trusted privacy computing framework "argot", flexible assembly of mainstream technologies, developer friendly layered design
文档编辑之markdown语法(typora)
Reprint: defect detection technology of industrial components based on deep learning
I want to say more about this communication failure
STM32+MFRC522完成IC卡号读取、密码修改、数据读写
UDP protocol: simple because of good nature, it is inevitable to encounter "city can play"
TCP packet sticking problem
Brief description of SQL optimization problems
從交互模型中蒸餾知識!中科大&美團提出VIRT,兼具雙塔模型的效率和交互模型的性能,在文本匹配上實現性能和效率的平衡!...
1700C - Helping the Nature
STM32按键状态机2——状态简化与增加长按功能
d绑定函数