vue h5移动端查看大图组件(可缩放)

找了很多查看大图的组件发现都没办法自定义样式,或不能缩放(wc-viewer   v-viewer ),于是就自己写了一个

主要思路就是运用swiper

                    

1使用方法

<template>
    <div class="size-detail">
        <bigImg :imgList="imgList" :show.sync="showBigImg"></bigImg>
        <button @click="showBigImg=!showBigImg">大图弹窗</button>
    </div>
</template>

<script>
import bigImg from "@/components/big-img";
export default {
    components: {
        bigImg,
    },
    data() {
        return {
            imgList: [
                {
                    url:
                        "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1547303486,112665549&fm=26&gp=0.jpg",
                },
                {
                    url:
                        "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1088335163,3385135939&fm=26&gp=0.jpg",
                },
                {
                    url:
                        "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimgo173.gda086.com%2Fimg2020%2F11%2F17%2F14%2F2020111736164127.jpg&refer=http%3A%2F%2Fimgo173.gda086.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1611822122&t=2578bfe10a9002d73a52deb6137ffe8d",
                },
                {
                    url:
                        "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=339612859,517673817&fm=26&gp=0.jpg",
                },
            ],
            showBigImg:false,
        };
    },
};
</script>

<style lang="scss" scoped>

</style>

2.组件big-img.vue

<template>
    <div
        class="big-img"
        :class="{hideo:!show,fadeIn:show}"
        @touchmove.prevent
    >
        <div
            class="icon-close"
            @click="onClose"
        >
            <img src="../images/icon-close.png">
        </div>
        <div class="content">
            <swiper
                :options="swiperOption"
                ref="myswiper"
            >
                <swiper-slide
                    v-for="(item, index) in imgList"
                    :key="index"
                >
                    <div class="swiper-zoom-container">
                        <img
                            class="slide-img"
                            :src="item.url"
                        >
                    </div>
                </swiper-slide>
            </swiper>
        </div>
        <div class="page">{{currIndex}}/{{imgList.length||0}}</div>
    </div>
</template>
<script>
import "swiper/dist/css/swiper.css";
import { swiper, swiperSlide } from "vue-awesome-swiper";
export default {
    components: {
        swiper,
        swiperSlide,
    },
    props: {
        show: {
            type: Boolean,
            default: false,
        },
        imgList: {
            type: Array,
        },
    },
    data() {
        return {
            currIndex: 1,
            swiperOption: {
                zoom: true,
                on: {
                    slideChange: (e) => {
                        this.currIndex =
                            this.$refs.myswiper.swiper.activeIndex + 1;
                    },
                },
            },
        };
    },
    created() {},
    methods: {
        onClose() {
            this.$emit("update:show", false);
        },
    },
};
</script>
<style lang="scss">
.big-img {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    .icon-close {
        position: fixed;
        left: 15px;
        top: 30px;
        padding: 10px;
        width: 42px;
        height: 42px;
        img {
            width: 22px;
            height: 22px;
        }
    }
    .content {
        width: 100%;
        overflow: hidden;
    }
    .swiper-zoom-container {
        height: 415px;
        display: flex;
        align-items: center;
        justify-content: center;
        .slide-img {
            width: 100%;
        }
    }
    .page {
        width: 100%;
        font-size: 14px;
        font-weight: 400;
        color: #ffffff;
        text-align: center;
        position: absolute;
        left: 0;
        bottom: 40px;
    }
}
.hideo {
    display: none !important;
}
.fadeIn {
    -webkit-animation: fadeInDown 0.2s forwards;
    animation: fadeInDown 0.2s forwards;
}

@keyframes fadeInDown {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

@-webkit-keyframes fadeInDown {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}
</style>

样式可自行修改

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Vue是一种用于构建用户界面的JavaScript框架,适用于各种平台,包括H5移动。使用Vue来写H5移动应用具有以下几个优势。 首先,Vue提供了丰富的组件库和生态系统,方便我们快速构建出符合H5移动需求的用户界面。我们可以使用Vue组件来封装各种常见的移动UI元素,例如按钮、弹窗、导航栏等,以减少我们的开发时间和工作量。 其次,Vue具有响应式的数据绑定机制,能够方便地将数据和视进行关联。在H5移动应用中,我们常常需要根据用户的操作改变界面的显示和行为,通过Vue的数据绑定,我们可以很容易地实现这一需求,从而提升用户体验。 此外,Vue还支持组件间的通信和交互。在H5移动应用中,各个组件之间经常需要进行数据传递和事件触发,Vue提供了一系列的机制,例如props和emit,来实现组件间的数据传递和通信,从而使得我们的应用更加灵活和可维护。 最后,Vue还有一些针对H5移动的特性和优化。例如,Vue可以通过Webpack等打包工具将代码进行优化和压,减小文件大小,提高页面加载速度;另外,Vue还支持使用Vue Router进行页面路由管理,使用Vuex进行全局状态管理,来满足复杂H5应用的需求。 综上所述,Vue是一种适用于H5移动的强大框架,它能够帮助我们快速构建出漂亮、高效的移动应用,提升用户体验,同时还具备灵活性和可维护性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值