关于移动端使用echarts点击图标外部不能关闭tooltip的问题
2024-08-23 13:43:56
新建一个mixin文件 粘贴如下代码:
1 /**
2 * 1. 需要将echart实例赋值为 this.echartsInstance `echartsInstance` echarts 带s
3 * 2. echarts所在的组件大小应该跟echarts图表实际大小相差不多
4 * 3. 引入即可,无需编写其他代码
5 */
6 export const mixinAutoHideTooltip = {
7 mounted() {
8 this.mAutoHideTooltip(this.$el);
9 },
10 data() {
11 this.mIsSelfTouch = false;
12 return {};
13 },
14 beforeDestroy() {
15 this.mRemoveListeners(this.$el);
16 },
17 methods: {
18 mAutoHideTooltip(dom) {
19 dom.addEventListener('touchstart', this.mHandleContainerTouchStart);
20 dom.addEventListener('touchend', this.mHandleContainerTouchEnd);
21 document.addEventListener('touchstart', this.mHandleDomcumentTouchStart);
22 },
23 mRemoveListeners(dom) {
24 dom.removeEventListener('touchstart', this.mHandleContainerTouchStart);
25 dom.removeEventListener('touchend', this.mHandleContainerTouchEnd);
26 document.removeEventListener('touchstart', this.mHandleDomcumentTouchStart);
27 },
28 mHandleContainerTouchStart() {
29 this.mIsSelfTouch = true;
30 },
31 mHandleContainerTouchEnd() {
32 this.mIsSelfTouch = false;
33 },
34 mHandleDomcumentTouchStart() {
35 if (this.mIsSelfTouch) return;
36 this.echartsInstance && this.mHideTooltip(this.echartsInstance);
37 },
38 mHideTooltip(echartsInstance) {
39 echartsInstance.dispatchAction({
40 type: 'updateAxisPointer',
41 currTrigger: 'mousemove',
42 x: 0,
43 y: 0
44 });
45 }
46 }
47 };
使用时如下:
最新文章
- 每天一个Linux命令
- 《挑战程序设计竞赛》 4.1.1 矩阵 P286
- 65.OV7725图像倒置180度
- 【转载】错误:ORA-28002: the password will expire within 7 days 解决方法
- 使用log4javascript记录日志
- RSYSLOG没那么简单
- Mysql学习(慕课学习笔记7)修改数据表(下)
- 一个Java对象到底占多大内存?(转)
- iPhone 6 首发无大陆,DevStore要去香港吗?
- 【百度地图API】如何激发手机的高分辨率
- intellij idea 在什么地方打开终端Terminal
- sed 命令替换字符串
- Chromecast
- BZOJ5210 最大连通子块和 【树链剖分】【堆】【动态DP】
- Python3 字典 setdefault() 方法
- python3字符串操作
- 结对项目——Core设计与实现
- 实现django admin后台到xadmin后台的转变
- 让SH/BAT脚本定位到运行目录的相对位置,实现其脚本可在任意运行目录下被正确执行
- 【CJOJ2433】陌上花开 树状数组套替罪羊树
热门文章
- Clickhouse表引擎之MergeTree
- 基于 RocketMQ 的 Dubbo-go 通信新范式
- linux常用指令记录
- 【SQL基础】多表查询:子查询、连接查询(JOIN)、组合查询(UNION集合运算)
- org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = character varying
- instanceof和Class.isAssignableFrom的区别
- 配置 DosBox
- Python:多进程并行编程与进程池
- Django聚合函数与分组查询
- jdk调度任务线程池ScheduledThreadPoolExecutor工作原理解析