美文网首页
如何使用 vue-preview 缩略图

如何使用 vue-preview 缩略图

作者: forever_bin | 来源:发表于2019-07-24 09:24 被阅读0次

1.首先安装 vue-preview 插件

npm i vue-preview -S

2.然后在 mian.js入口中引入

import VuePreview from ‘vue-preview’

Vue.use(VuePreview)

组件:

<div class="thumbs">

  <vue-preview :slides="details" class="preview" >

</div>

script 部分

data() {

return {

id:this.$route.params.id,//从路由中获取的图片id

    details: [],//缩略图的数组

  }

},

created() {

  this.setPreview();

},

methods: {

getPhotoInfo() {

axios.get('/api/getimageInfo/' +this.id).then(res => {

if (res.data.status ==0) {

this.photoInfo = res.data.message[0];

      }

})

},

  setPreview:function () {

axios.get('/api/getthumimages/' +this.id).then(res => {

if (res.data.status ==0) {

res.data.message.forEach(item => {

item.w =600;

          item.h =400;

          item.msrc = item.src;

        });

        //把完整的数据保存到 details中

        this.details = res.data.message;

      }

})

}

},

style部分

.thumbs {

/deep/ .my-gallery {

display:flex;

    flex-wrap:wrap;

    figure {

width:30%;

      margin:5px;

      img {

width:100%;

box-shadow:0 0 8px #999;

      }

}

}

以上完成后,就可以看到有样式的缩略图了

相关文章

网友评论

      本文标题:如何使用 vue-preview 缩略图

      本文链接:https://www.haomeiwen.com/subject/yemalctx.html