鍍金池/ 問(wèn)答/HTML/ 滑動(dòng)事件與點(diǎn)擊事件同時(shí)操作Vue掛載DOM,導(dǎo)致界面重疊,有什么方法可以解決?

滑動(dòng)事件與點(diǎn)擊事件同時(shí)操作Vue掛載DOM,導(dǎo)致界面重疊,有什么方法可以解決?

使用mint-ui繪制滑動(dòng)界面,界面如下:
主界面
主界面

菜單:

['CREDIT', 'DEBIT', 'EBT', 'GIFT', 'FUNC']

子菜單:

[
    'CREDIT': ['Sale', 'Forced', 'Return', 'Balance', 'Void Sale', 'Void Forced', 'Void Return'],
    'DEBIT': [],
    ...
]

兩種界面切換方式:

  • 滑動(dòng)過(guò)程界面切換,'CREDIT'-->'DEBIT'-->'EBT'-->'GIFT'-->'FUNC'-->'CREDIT'
  • 單擊菜單界面切換,例如:?jiǎn)螕?GIFT',顯示'GIFT'子菜單
問(wèn)題:滑動(dòng)(touchstart, touchmove, touchend)與點(diǎn)擊事件(click)同時(shí)發(fā)生時(shí),子菜單重疊顯示:
圖片描述

滑動(dòng)實(shí)現(xiàn)代碼參見(jiàn):mint-ui(swipe)
單擊事件修改swipe組件的reInitPages函數(shù)實(shí)現(xiàn):

reInitPages(gotoIndex) {
  const children = this.$children
  this.noDrag = children.length === 1 && this.noDragWhenSingle

  const pages = []
  let intDefaultIndex = Math.floor(this.defaultIndex)
  if (gotoIndex !== undefined) {
    intDefaultIndex = Math.floor(gotoIndex)
  }

  const defaultIndex = (intDefaultIndex >= 0 && intDefaultIndex < children.length) ? intDefaultIndex : 0
  this.index = defaultIndex

  children.forEach((child, index) => {
    pages.push(child.$el)

    removeClass(child.$el, 'is-active')

    if (index === defaultIndex) {
      addClass(child.$el, 'is-active')
    }
  })

  this.pages = pages
}

有什么辦法可以解決顯示重疊問(wèn)題?

回答
編輯回答
法克魷

不需要寫(xiě)click事件,在touchstart和touchend中控制,類(lèi)似下面一個(gè)例子,click就是touchstart和touchend事件只不過(guò)沒(méi)有touchmove。如果你想要在touchmove中控制可以單獨(dú)寫(xiě)一個(gè)方法
element.addEventListener('touchstart', (event) => {

    if (this.prevent) {
      event.preventDefault();
   
    }
     this.dragging = true;
    this.doOnTouchStart(event);
  });

element.addEventListener('touchmove', (event) => {

    if (!this.dragging) return;
    this.doOnTouchMove(event);
  });
  element.addEventListener('touchend', (event) => {
    if (this.userScrolling) {
      this.dragging = false;
      this.dragState = {};
      return;
    }
    if (!this.dragging) return;
    this.doOnTouchEnd(event);
    this.dragging = false;
  });
  
2017年7月21日 08:00
編輯回答
初心

沒(méi)看明白你這個(gè)到底是樣式問(wèn)題導(dǎo)致還是點(diǎn)擊事件與滑動(dòng)事件沖突了。

2018年6月29日 03:55