vue 綁定使用 touchstart touchmove touchend解析
綁定使用 touchstart touchmove touchend
今天要做一個頁面div長按后觸發(fā)事件,簡單學(xué)習(xí)后實現(xiàn)如下:
先看代碼:
<template> ? <div> ? ? <div class="test" @touchstart="gtouchstart()" @touchmove="gtouchmove()" @touchend="gtouchend()">試一試呀!</div> ? </div> </template>
<script> export default { ? data () { ? ? return {? ? ? ?? ? ? } ? }, ? ? methods:{ ? ? ? ? gtouchstart(){ ? ? ? ? ? ? window.console.log('1,按下啦啦啦啦啦') ? ? ? ? }, ? ? ? ? gtouchmove(){ ? ? ? ? ? ? window.console.log('2,按下并且在移動呢') ? ? ? ? }, ? ? ? ? gtouchend(){ ? ? ? ? ? ? window.console.log('3,松開啦啦啦啦啦') ? ? ? ? } ? ? } } </script>
<style scoped> ? ? .test{ ? ? ? ? width: 100%; ? ? ? ? height: 50px;; ? ? ? ? text-align: center; ? ? ? ? background-color: red; ? ? ? ? line-height: 50px; ? ? ? ? font-size: 50px; ? ? }? </style>
看結(jié)果:
鼠標(biāo)在紅色區(qū)域內(nèi)按下會輸出1,
按下鼠標(biāo)不松開然后移動會輸出2,
松開后就會輸出3,
根據(jù)自己的情況在三個函數(shù)里寫入相應(yīng)的功能。
解決touchstart touchend事件無效失效
?? ?<van-button ? ? ? ? ? :disabled="isLoading" ? ? ? ? ? plain ? ? ? ? ? type="info" ? ? ? ? ? @touchstart.native.prevent="touchstart" ? ? ? ? ? @touchend.native.prevent="touchend" ? ? ? ? ? style="width:40%;height: 40px;" ? ? ? ? ? round>對比原圖 ? ? ? ? </van-button>
@touchstart.native.prevent=“touchstart” @touchend.native.prevent=“touchend”
增加 .native.prevent
? ? touchstart() { ? ? ? console.log('touchstart') ? ? }, ? ? touchend() { ? ? ? console.log('touchend') ? ? },
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue中后端做Excel導(dǎo)出功能返回數(shù)據(jù)流前端的處理操作
這篇文章主要介紹了vue中后端做Excel導(dǎo)出功能返回數(shù)據(jù)流前端的處理操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09基于vue3+antDesign2+echarts?實現(xiàn)雷達(dá)圖效果
這篇文章主要介紹了基于vue3+antDesign2+echarts?實現(xiàn)雷達(dá)圖,本文通過實例代碼圖文相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08基于 Vue.js 2.0 酷炫自適應(yīng)背景視頻登錄頁面實現(xiàn)方式
本文講述如何實現(xiàn)擁有酷炫背景視頻的登錄頁面,瀏覽器窗口隨意拉伸,背景視頻及前景登錄組件均能完美適配,背景視頻可始終鋪滿窗口,前景組件始終居中,視頻的內(nèi)容始終得到最大限度的保留,可以得到最好的視覺效果2018-01-01淺談vue的iview列表table render函數(shù)設(shè)置DOM屬性值的方法
下面小編就為大家?guī)硪黄獪\談vue的iview列表table render函數(shù)設(shè)置DOM屬性值的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09