欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue中如何使用vue-touch插件

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

vue中使用vue-touch

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

首先在vue項目中安裝vue-touch

npm install vue-touch@next --save

然后在main.js或mian.ts上導入并使用:

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

使用<v-touch></v-touch>來包裹要使用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ù)名( )"來使用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實現(xiàn)移動端左右滑動屏幕切換頁面(左右滑動切換路由)

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  //設置左右滑動的距離
}
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.在某頁面中

<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頁
      this.$router.push({'path':'/goods'});
    },
    swiperright: function () { //右滑切換到detail頁
      this.$router.push({'path':'/detail'});
    }
  }
}
</script>

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

相關文章

最新評論