官网地址https://youzan.github.io/vant/?source=vuejsorg#/zh-CN/swipe

1.安装依赖

  1. yarn add vant

2.main.js中引入依赖

  1. import Vant from 'vant'
  2. import 'vant/lib/index.css' //vant
  3. import { Swipe, SwipeItem } from 'vant';
  4. import { Lazyload } from 'vant';
  5. Vue.use(Swipe).use(SwipeItem);
  6. Vue.use(Lazyload);

3.使用.vue文件中

  1. <template>
  2. <div>
  3. <van-swipe :autoplay="3000">
  4. <van-swipe-item v-for="(image, index) in images" :key="index" @click="handleClick(index)">
  5. <img v-lazy="image" />
  6. </van-swipe-item>
  7. </van-swipe>
  8. </div>
  9. </template>
  10. <script>
  11. import {ImagePreview} from 'vant'
  12. export default {
  13. name:"Music",
  14. data(){
  15. return{
  16. images:[
  17. require('@/assets/logo.png'), //图片显示不了,要使用镜像
  18. require('@/assets/logo.png'),
  19. ]
  20. }
  21. },
  22. methods:{
  23. handleClick(index){ //点击事件,点击查看大图
  24. const instance=ImagePreview({
  25. images:this.images,
  26. asyncClose:true,
  27. startPosition:index,
  28. onClose(){
  29. instance.close()
  30. }
  31. });
  32. }
  33. }
  34. }
  35. </script>
  36. <style scoped>
  37. </style>