vue中如何使用vue-touch插件
vue中使用vue-touch
如果想让vue能够监听移动端的上滑、下滑、左滑、点击等等动作,可以使用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的事件名="函数名( )"来使用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实现移动端左右滑动屏幕切换页面(左右滑动切换路由)
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">
内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容内容
</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内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
vue2 el-table行悬停时弹出提示信息el-popover的实现
本文主要介绍了vue2 el-table行悬停时弹出提示信息el-popover的实现,用到了cell-mouse-enter、cell-mouse-leave两个事件,具有一定的参考价值,感兴趣的可以了解一下2024-01-01
Vue + Webpack + Vue-loader学习教程之功能介绍篇
这篇文章主要介绍了关于Vue + Webpack + Vue-loader功能介绍的相关资料,文中介绍的非常详细,相信对大家具有一定的参考价值,需要的朋友们下面来一起看看吧。2017-03-03
vue百度地图通过地址名称获取地址的经纬度gps问题(具体步骤)
在Vue项目中,可以通过使用百度地图JavaScript API来实现根据地址名称获取经纬度GPS的功能,本文分步骤给大家详细讲解vue百度地图获取经纬度的实例,感兴趣的朋友一起看看吧2023-05-05
vue3父子通信ref,toRef,toRefs使用实例详解
这篇文章主要介绍了vue3父子通信ref,toRef,toRefs使用实例详解,分别介绍了ref是什么、toRef是什么及toRefs是什么和最佳使用方式,结合示例代码给大家讲解的非常详细,需要的朋友可以参考下2023-10-10
使用element ui中el-table-column进行自定义校验
这篇文章主要介绍了使用element ui中el-table-column进行自定义校验方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2024-08-08
Vue 数值改变页面没有刷新的问题解决(数据改变视图不更新的问题)
这篇文章主要介绍了Vue 数值改变页面没有刷新的问题解决(数据改变视图不更新的问题),本文结合实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2023-09-09
Vue3组合式函数Composable实战ref和unref使用
这篇文章主要为大家介绍了Vue3组合式函数Composable实战ref和unref使用详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-06-06


最新评论