vue移動(dòng)端如何解決click事件延遲,封裝tap等事件
更新時(shí)間:2022年03月28日 08:51:42 作者:狗蛋*
這篇文章主要介紹了vue移動(dòng)端如何解決click事件延遲,封裝tap等事件,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
移動(dòng)端解決click事件延遲,封裝tap等事件
下載vue-touch.js
引入:
<script src="js/vue-touch.js" type="text/javascript" charset="utf-8"></script>
導(dǎo)航條tab:
<div>
? ? ? ? ? ? ? ? <ul>
? ? ? ? ? ? ? ? ? ? <li v-tap="{fn:vueTouch,active:0}" :class="{'activezixun':active===0}">全部</li>
? ? ? ? ? ? ? ? ? ? <li v-tap="{fn:vueTouch,active:1}" :class="{'activezixun':active===1}">養(yǎng)車知識(shí)</li>
? ? ? ? ? ? ? ? ? ? <li v-tap="{fn:vueTouch,active:2}" :class="{'activezixun':active===2}">愛車保養(yǎng)</li>
? ? ? ? ? ? ? ? ? ? <li v-tap="{fn:vueTouch,active:3}" :class="{'activezixun':active===3}">汽車維修</li>
? ? ? ? ? ? ? ? </ul>
? ? ? ? ? ? </div>tab對(duì)應(yīng)的列表頁:
<div class="zixunQuanbu" v-show="active===0">
<div class="items">
<a href="zixunItems1.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<img class="items-img" src="img/zixun1.png"/>
<p class="items-title">跑了10萬公里的車,相當(dāng)于人的多少歲別在“黃金車齡”把車賣了</p>
<p class="items-jianjie"><span class="jianjie-one">對(duì)于一輛車來說,它在正常情況下可供時(shí)間</span></p>
<p class="items-time">2019-04-20 <span class="mui-icon iconfont iconyanjing"></span><span class="liulanliang">1265</span></p>
</a>
</div>
</div>
<!--養(yǎng)車知識(shí)-->
<div class="zixunQuanbu" v-show="active===1">
<div class="items">
<a href="zixunItems1.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<img class="items-img" src="img/zixun2.png"/>
<p class="items-title">開車是累了記得打開“防疲勞按鍵”, 有人直到車子報(bào)廢也沒有開過</p>
<p class="items-jianjie"><span class="jianjie-one">其實(shí)疲勞駕駛也是有預(yù)防措施的,汽車上有</span></p>
<p class="items-time">2019-03-20 <span class="mui-icon iconfont iconyanjing"></span><span class="liulanliang">1265</span></p>
</a>
</div>
</div>
<!--愛車保養(yǎng)-->
<div class="zixunQuanbu" v-show="active===2">
<div class="items">
<a href="zixunItems1.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<img class="items-img" src="img/zixun3.png"/>
<p class="items-title">停車后直接就熄火下車?老司機(jī)告訴 你:發(fā)動(dòng)機(jī)至少折壽5年!</p>
<p class="items-jianjie"><span class="jianjie-one">在停車熄火之前隨手多做一步,能讓把發(fā)動(dòng)</span></p>
<p class="items-time">2019-02-20 <span class="mui-icon iconfont iconyanjing"></span><span class="liulanliang">1265</span></p>
</a>
</div>
</div>
<!--汽車維修-->
<div class="zixunQuanbu" v-show="active===3">
<div class="items">
<a href="zixunItems1.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<img class="items-img" src="img/zixun4.png"/>
<p class="items-title">這些地方的螺絲被動(dòng)過,說明你買的是 事故車,一定要注意了</p>
<p class="items-jianjie"><span class="jianjie-one">隨著汽車市場的不斷發(fā)展車子的保有量也不斷</span></p>
<p class="items-time">2019-03-20 <span class="mui-icon iconfont iconyanjing"></span><span class="liulanliang">1265</span></p>
</a>
</div>
</div>vue.js:
var vm = new Vue({
? ? ? ? ? ? ? ? el: '#zixunClass',
? ? ? ? ? ? ? ? data: {
? ? ? ? ? ? ? ? ? ? "active": 0
? ? ? ? ? ? ? ? },
? ? ? ? ? ? ? ? methods: {
? ? ? ? ? ? ? ? ? ? vueTouch:function(a){
? ? ? ? ? ? ? ? ? ? ? ? this.active=a.active;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? })移動(dòng)端click事件失效
可能是你使用了better-scroll,默認(rèn)它會(huì)阻止touch事件。所以在配置中需要加上click: true
例:
import BScroll from 'better-scroll'
mounted() {
? ? this.scroll = new BScroll(this.$refs.search, {mouseWheel: true, click: true, tap: true })
? },以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue移動(dòng)端時(shí)彈出側(cè)邊抽屜菜單效果
這篇文章主要介紹了vue移動(dòng)端時(shí)彈出側(cè)邊抽屜菜單,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06
vue實(shí)現(xiàn)循環(huán)滾動(dòng)列表
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)循環(huán)滾動(dòng)列表,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-06-06
深入理解Vue keep-alive及實(shí)踐總結(jié)
這篇文章主要介紹了深入理解Vue keep-alive及實(shí)踐總結(jié),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08

