亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue中如何使用vue-touch插件

 更新時(shí)間:2023年07月07日 10:11:48   作者:前端小凱  
這篇文章主要介紹了vue中使用vue-touch插件的方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

vue中使用vue-touch

如果想讓vue能夠監(jiān)聽(tīng)移動(dòng)端的上滑、下滑、左滑、點(diǎn)擊等等動(dòng)作,可以使用vue-touch插件。vue-touch的使用十分簡(jiǎn)單。

首先在vue項(xiàng)目中安裝vue-touch

npm install vue-touch@next --save

然后在main.js或mian.ts上導(dǎo)入并使用:

import VueTouch from "vue-touch";
Vue.use(VueTouch, {name: "v-touch"});

使用<v-touch></v-touch>來(lái)包裹要使用vue-touch的元素

 <v-touch @swipeleft="nowLeft()" @swiperight="nowRight()">
        <ul class="list">
          <li v-for="(item, index) in move_nowData" :key="item.id">
            <div>
              <img :src="item.cover" />
            </div>
            <h3>{{ item.title }}</h3>
            <p>{{ item.rate }}</p>
          </li>
        </ul>
</v-touch>

使用@touch.js的事件名="函數(shù)名( )"來(lái)使用vue-touch

methods: {
    nowLeft() {
      // 獲取list
      let now = document.getElementsByClassName("list")[0];
      now.style.transform += "translateX(-30rem)";
      now.style.transition = "all ease 0.5s";
    },
    nowRight() {
      // 獲取list
      let now = document.getElementsByClassName("list")[0];
      now.style.transform += "translateX(30rem)";
      now.style.transition = "all ease 0.5s";
      },
  },

touch.js常用事件

使用vue-touch實(shí)現(xiàn)移動(dòng)端左右滑動(dòng)屏幕切換頁(yè)面(左右滑動(dòng)切換路由)

1.安裝vue-touch

npm install vue-touch@next --save

2.在main.js中引入

import  VueTouch from 'vue-touch'
Vue.use(VueTouch,{name:'v-touch'})
VueTouch.config.swipe = {
  threshold:50  //設(shè)置左右滑動(dòng)的距離
}
import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import GoodsList from '@/view/GoodList'
import GoodDetail from '@/view/GoodDetail'
Vue.use(Router)
export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },{
      path:'/goods',
      name:'GoodsList',
      component:GoodsList
    },{
      path:'/detail',
      name:'GoodDetail',
      component:GoodDetail
    }
  ]
})

4.在某頁(yè)面中

<template>
  <div class="hello">
    <v-touch v-on:swipeleft="swiperleft"  v-on:swiperight="swiperright" class="wrapper">
      內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容
    </v-touch>
  </div>
</template>
<script>
export default {
  name: 'HelloWorld',
  methods:{
    swiperleft: function () {  //左劃切換到goods頁(yè)
      this.$router.push({'path':'/goods'});
    },
    swiperright: function () { //右滑切換到detail頁(yè)
      this.$router.push({'path':'/detail'});
    }
  }
}
</script>

到此這篇關(guān)于vue中使用vue-touch的文章就介紹到這了,更多相關(guān)vue使用vue-touch內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論