当前位置:网站首页>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)
边栏推荐
- std::true_type和std::false_type
- 小程序在产业互联网中的作用
- Jerry's updated equipment resource document [chapter]
- 重磅硬核 | 一文聊透对象在 JVM 中的内存布局,以及内存对齐和压缩指针的原理及应用
- Windows connects redis installed on Linux
- F200——搭载基于模型设计的国产开源飞控系统无人机
- MS-TCT:Inria&SBU提出用于动作检测的多尺度时间Transformer,效果SOTA!已开源!(CVPR2022)...
- Grafana 9.0 is officially released! It's the strongest!
- STM32+ENC28J60+UIP协议栈实现WEB服务器示例
- 编译原理——自上而下分析与递归下降分析构造(笔记)
猜你喜欢

Grafana 9.0 is officially released! It's the strongest!

Easy to use PDF to SVG program

Scratch epidemic isolation and nucleic acid detection Analog Electronics Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022

Virtual machine VirtualBox and vagrant installation

阿里云国际版ECS云服务器无法登录宝塔面板控制台

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

Top command details

Excellent open source fonts for programmers

Heavy! Ant open source trusted privacy computing framework "argot", flexible assembly of mainstream technologies, developer friendly layered design

虚拟机VirtualBox和Vagrant安装
随机推荐
Codeforces Round #803 (Div. 2)
MSF横向之MSF端口转发+路由表+SOCKS5+proxychains
IP, subnet mask, gateway, default gateway
虚拟机VirtualBox和Vagrant安装
Excellent open source fonts for programmers
Fleet tutorial 13 basic introduction to listview's most commonly used scroll controls (tutorial includes source code)
UDP protocol: simple because of good nature, it is inevitable to encounter "city can play"
STM32按键状态机2——状态简化与增加长按功能
1700C - Helping the Nature
The latest financial report release + tmall 618 double top, Nike energy leads the next 50 years
declval(指导函数返回值范例)
Codeforces Round #803 (Div. 2)
《ASP.NET Core 6框架揭秘》样章发布[200页/5章]
Jerry's watch deletes the existing dial file [chapter]
C语言通过指针交换两个数
Kill -9 system call used by PID to kill process
Recommend easy-to-use backstage management scaffolding, everyone open source
Virtual machine VirtualBox and vagrant installation
Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)
OpenEuler 会长久吗