新建一个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 };

使用时如下:

最新文章

  1. 每天一个Linux命令
  2. 《挑战程序设计竞赛》 4.1.1 矩阵 P286
  3. 65.OV7725图像倒置180度
  4. 【转载】错误:ORA-28002: the password will expire within 7 days 解决方法
  5. 使用log4javascript记录日志
  6. RSYSLOG没那么简单
  7. Mysql学习(慕课学习笔记7)修改数据表(下)
  8. 一个Java对象到底占多大内存?(转)
  9. iPhone 6 首发无大陆,DevStore要去香港吗?
  10. 【百度地图API】如何激发手机的高分辨率
  11. intellij idea 在什么地方打开终端Terminal
  12. sed 命令替换字符串
  13. Chromecast
  14. BZOJ5210 最大连通子块和 【树链剖分】【堆】【动态DP】
  15. Python3 字典 setdefault() 方法
  16. python3字符串操作
  17. 结对项目——Core设计与实现
  18. 实现django admin后台到xadmin后台的转变
  19. 让SH/BAT脚本定位到运行目录的相对位置,实现其脚本可在任意运行目录下被正确执行
  20. 【CJOJ2433】陌上花开 树状数组套替罪羊树

热门文章

  1. Clickhouse表引擎之MergeTree
  2. 基于 RocketMQ 的 Dubbo-go 通信新范式
  3. linux常用指令记录
  4. 【SQL基础】多表查询:子查询、连接查询(JOIN)、组合查询(UNION集合运算)
  5. org.springframework.jdbc.BadSqlGrammarException: ### Error querying database. Cause: org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint = character varying
  6. instanceof和Class.isAssignableFrom的区别
  7. 配置 DosBox
  8. Python:多进程并行编程与进程池
  9. Django聚合函数与分组查询
  10. jdk调度任务线程池ScheduledThreadPoolExecutor工作原理解析