其實很簡單只是用了js的幾個函數vue
substr
unshift
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) }