Vue图片预览插件viewerjs

灰太狼 2021-12-16 08:13 1329阅读 0赞

GitHub地址:https://github.com/fengyuanchen/viewerjs 。
1、安装:npm install v-viewer --save
2、在vue中引用

  1. import Viewer from 'v-viewer'
  2. import 'viewerjs/dist/viewer.css'

3、vue注册调用,再调用setDefaults方法自定义配置。

  1. Vue.use(Viewer);
  2. Viewer.setDefaults({
  3. 'inline':true,
  4. 'button':true, //右上角按钮
  5. "navbar": true, //底部缩略图
  6. "title": true, //当前图片标题
  7. "toolbar": true, //底部工具栏
  8. "tooltip": true, //显示缩放百分比
  9. "movable": true, //是否可以移动
  10. "zoomable": true, //是否可以缩放
  11. "rotatable": true, //是否可旋转
  12. "scalable": true, //是否可翻转
  13. "transition": true, //使用 CSS3 过度
  14. "fullscreen": true, //播放时是否全屏
  15. "keyboard": true, //是否支持键盘
  16. "url": "data-source",
  17. ready: function (e) {
  18. console.log(e.type,'组件以初始化');
  19. },
  20. show: function (e) {
  21. console.log(e.type,'图片显示开始');
  22. },
  23. shown: function (e) {
  24. console.log(e.type,'图片显示结束');
  25. },
  26. hide: function (e) {
  27. console.log(e.type,'图片隐藏完成');
  28. },
  29. hidden: function (e) {
  30. console.log(e.type,'图片隐藏结束');
  31. },
  32. view: function (e) {
  33. console.log(e.type,'视图开始');
  34. },
  35. viewed: function (e) {
  36. console.log(e.type,'视图结束');
  37. // 索引为 1 的图片旋转20度
  38. if(e.detail.index === 1){
  39. this.viewer.rotate(20);
  40. }
  41. },
  42. zoom: function (e) {
  43. console.log(e.type,'图片缩放开始');
  44. },
  45. zoomed: function (e) {
  46. console.log(e.type,'图片缩放结束');
  47. }
  48. });

在这里插入图片描述
4、使用

  1. <div>
  2. <viewer :images="images" style="height: 800px;">
  3. <img v-for="item in images" :src="item.src" :key="item.index" height="100">
  4. </viewer>
  5. </div>
  6. data() {
  7. return {
  8. images:[
  9. {src:'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3272199364,3404297250&fm=26&gp=0.jpg',index:1},
  10. {src:'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3267295166,2381808815&fm=26&gp=0.jpg',index:2},
  11. {src:'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3429654663,2972188411&fm=26&gp=0.jpg',index:3},
  12. {src:'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3597323878,2962972725&fm=26&gp=0.jpg',index:4},
  13. ]
  14. }
  15. }

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,1329人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Bootstrap

    Bootstrap自带12种jQuery插件,可以给站点添加更多的互动。 站点引用Bootstrap插件的方式有两种 1.单独引用:使用个别的.js文件,一些插件和cs