如何使用 vue-preview 縮略圖

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: [],//縮略圖的數(shù)組

? }

},

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;

? ? ? ? });

? ? ? ? //把完整的數(shù)據(jù)保存到 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;

? ? ? }

}

}

以上完成后,就可以看到有樣式的縮略圖了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容