vue+elementui实现移动端图片手指滑动

一起探讨学习

欢迎大家进群,一起讨论学习

每天给大家提供技术干货

在这里插入图片描述

博主技术笔记 https://notes.xiyankt.com


博主开源微服架构前后端分离技术博客项目源码地址,欢迎各位star https://gitee.com/bright-boy/xiyan-blog


vue实现移动端图片手指滑动

安装

npm install vue-touch@next --save

main.js中引入:

import VueTouch from 'vue-touch'
Vue.use(VueTouch, {name: 'v-touch'})
<el-carousel :interval="4000" indicator-position="outside" height="840px" ref="carousel">
      <el-carousel-item v-for="(item,index) in banners" :key="item.url">
        <v-touch :swipe-options="{direction: 'horizontal'}" v-on:swipeleft="swiperleft(index)" v-on:swiperight="swiperright(index)" class="wrapper">
        <div class="menu-container" ref="menuContainer">   
          <img v-lazy="item.url"/>
        </div>
       </v-touch>
      </el-carousel-item>
    </el-carousel>
  methods: {
    //设置滑动切换轮播图
    swiperleft: function (index) {
      //上一页
      this.$refs.carousel.prev();
      //设置幻灯片的索引
      this.$refs.carousel.setActiveItem(index - 1);
    },
    swiperright: function (index) {
      //下一页
      this.$refs.carousel.next();
      this.$refs.carousel.setActiveItem(index + 1);
    },
  },

发现BUG:vue-touch不能上下滑动的问题

.wrapper {
  touch-action: pan-y !important;
}
  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
VueElement UI中实现移动端禁止截屏和录屏可以通过以下步骤来实现: 1. 阻止截屏:可以通过监听`window`对象的`keyup`、`keydown`和`keypress`事件,当用户按下截屏快捷键时,阻止默认行为。 ```javascript mounted() { window.addEventListener('keyup', this.handleScreenCapture); window.addEventListener('keydown', this.handleScreenCapture); window.addEventListener('keypress', this.handleScreenCapture); }, methods: { handleScreenCapture(event) { if (event.keyCode === 44) { // PrtSc键的keyCode为44 event.preventDefault(); } } }, beforeDestroy() { window.removeEventListener('keyup', this.handleScreenCapture); window.removeEventListener('keydown', this.handleScreenCapture); window.removeEventListener('keypress', this.handleScreenCapture); } ``` 2. 阻止录屏:目前Web端无法直接阻止移动设备上的录屏行为,但可以通过添加一层透明的遮罩层来阻挡录屏软件的截屏功能。在Vue中,可以使用Element UI的`Dialog`组件来实现遮罩层。 ```vue <template> <div> <el-dialog :visible="dialogVisible" :center="true" :modal="false" :show-close="false" :close-on-click-modal="false"> <div class="dialog-content"> <p>禁止录屏</p> </div> </el-dialog> <!-- 页面其他内容 --> </div> </template> <script> export default { data() { return { dialogVisible: true }; } }; </script> <style> .dialog-content { width: 100vw; height: 100vh; background-color: rgba(0, 0, 0, 0.01); } </style> ``` 以上代码中,通过设置`dialogVisible`为`true`,使得`Dialog`组件显示为透明的全屏遮罩层。你可以根据需要自定义遮罩层的样式和内容。 请注意,这种方式只能防止一些常见录屏软件的截屏功能,无法完全阻止所有录屏行为。因为在移动设备上,录屏软件通常会使用系统级别的截屏权限,无法通过前端代码进行完全控制。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jmaes_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值