vue 綁定使用 touchstart touchmove touchend解析
綁定使用 touchstart touchmove touchend
今天要做一個頁面div長按后觸發(fā)事件,簡單學習后實現(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é)果:

鼠標在紅色區(qū)域內(nèi)按下會輸出1,

按下鼠標不松開然后移動會輸出2,

松開后就會輸出3,
根據(jù)自己的情況在三個函數(shù)里寫入相應的功能。
解決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)文章
Vue3+Canvas實現(xiàn)坦克大戰(zhàn)游戲(一)
這篇文章將利用Vue3和Canvas編寫一個童年經(jīng)典游戲—坦克大戰(zhàn),文中的示例代碼講解詳細,感興趣的小伙伴快來跟隨小編一起學習一下吧2022-03-03
vue中控制mock在開發(fā)環(huán)境使用,在生產(chǎn)環(huán)境禁用方式
這篇文章主要介紹了vue中控制mock在開發(fā)環(huán)境使用,在生產(chǎn)環(huán)境禁用方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
vue中父子組件傳值,解決鉤子函數(shù)mounted只運行一次的操作
這篇文章主要介紹了vue中父子組件傳值,解決鉤子函數(shù)mounted只運行一次的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07
解決vue watch數(shù)據(jù)的方法被調(diào)用了兩次的問題
這篇文章主要介紹了解決vue watch數(shù)據(jù)的方法被調(diào)用了兩次的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
vue webpack開發(fā)訪問后臺接口全局配置的方法
今天小編就為大家分享一篇vue webpack開發(fā)訪問后臺接口全局配置的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09

