使用vue-preview实现缩略图

本文详细介绍如何在Vue项目中使用vue-preview组件实现图片预览功能,包括安装、配置、使用及样式调整,帮助开发者快速上手。

1.项目中安装组件

npm i vue-preview -S

2.main.js中引入插件,挂载到Vue

import VuePreview from 'vue-preview';
Vue.use(VuePreview);

3.在组件中使用,代码如下(代码中数据为假数据,调后台接口请在methods中自行添加代码):

<!--缩略图区域-->
<template>
    <div class="photoinfo-container">
        <div class="thumbs">
            <vue-preview :slides="list" class="imgPrev"></vue-preview>
        </div>
    </div>
</template>
<script>
    //listTmp中各字段含义:
    //src:缩略图点开后图片
    //msrc:缩略图
    //w:缩略图点开后的宽度
    //h:缩略图点开后的高度
    var listTmp = [
        {
            src:"https://f12.baidu.com/it/u=1958490809,1691334580&fm=72",
            msrc:"https://f12.baidu.com/it/u=1958490809,1691334580&fm=72",
            w:600,
            h:400
        },
        {
            src:"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=547934426,2187279168&fm=15&gp=0.jpg",
            msrc:"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=547934426,2187279168&fm=15&gp=0.jpg",
            w:600,
            h:400
        },
        {
            src:"http://img.lanrentuku.com/img/allimg/1506/5-1506151506080-L.jpg",
            msrc:"http://img.lanrentuku.com/img/allimg/1506/5-1506151506080-L.jpg",
            w:600,
            h:400
        }
    ];
    export default {
        data(){
            return {
                list:listTmp//缩略图的数组
            }
        },
        methods:{
            
        }
    }
</script>

<style lang="scss">
<!--样式可以通过chrome的开发者工具,右键检查点击图片进行查看html样式的结构,style标签中不要使用scoped-->
    .photoinfo-container{
        .thumbs{
            .imgPrev{
                .my-gallery{
                    figure{
                        display: inline-block;
                        margin: 8px;
                    }
                    img{
                        width: 80px;
                        height: 60px;
                    }
                }
            }
        }
    }
</style>

4.运行效果如图:

评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值