mpvue——實現點擊數組內的某一元素進行置頂(排序第一)操做

前言

其實很簡單只是用了js的幾個函數vue

  1. substr
  2. unshift
  3. splice

完整代碼 | mpvue模仿QQgit

代碼

思路很簡單,獲取當前元素下標而後經過unshift函數將該值插入到數組第一位,再經過splice函數刪除該值github

核心代碼數組

listTop (e) {
      const that = this
      let index = e.currentTarget.dataset.eventid.substr(e.currentTarget.dataset.eventid.length - 1, 1)
      that.messageList.unshift(that.messageList[index])
      that.messageList.splice(++index, 1)
    }

效果圖

相關文章
相關標籤/搜索