vue项目中如何结合swiper实现图片左右滑动切换,下面web建站小编给大家详细介绍一下实现代码!
1、安装脚手架
npm install vue-awesome-swiper --save
2、main.js全局引用
import VueAwesomeSwiper from 'vue-awesome-swiper' Vue.user(VueAwesomeSwiper) import 'dist/swiper/swiper.css'
3、页面实现代码
<template>
<div>
<label>{{ time }}</label>
<div id="star-pic-vue">
<template v-if="data">
<img
v-for="(item, index) in images"
:src="item.url"
:key="index"
id="contract_url"
@click="enlargePic(index)"
/>
<template v-if="isDialogShow"> </template>
<el-dialog
:visible.sync="centerDialogVisible"
width="100%"
modal
close-on-click-modal
custom-class="dialog"
>
<swiper :options="swiperOption" ref="mySwiper" style="height: 100%;">
<swiper-slide v-for="(img, index) in images" :key="index">
<div>
<img :src="img.url" alt="" />
</div>
</swiper-slide>
</swiper>
</el-dialog>
</template>
</div>
</div>
</template>
<script>
import { swiper, swiperSlide } from "vue-awesome-swiper";
export default {
name: "PictureComponent",
props: ["data", "maxShow", "time"],
data() {
return {
centerDialogVisible: false,
showPic: "",
isDialogShow: false,
activeIndex: 1,
startX: 0,
swiperOption: {
width: window.innerWidth,
zoom: true,
initialSlide: 0
}
};
},
computed: {
images() {
if (this.data instanceof Array && this.data.length > 2) {
var value = this.data;
return value.splice(0, this.maxShow);
} else {
return this.data;
}
}
},
components: {
swiper,
swiperSlide
},
methods: {
// 放大图片
enlargePic(i) {
this.activeIndex = i;
this.isDialogShow = true;
this.$nextTick(() => {
var swiper = this.$refs.mySwiper.swiper;
swiper.activeIndex = i;
});
this.centerDialogVisible = true;
}
}
};
</script>
<style>
.timeline {
display: block;
margin: 10px 20px 5px;
}
#star-pic-vue .el-dialog__wrapper {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: auto;
margin: 0;
background: #171717;
}
#star-pic-vue {
width: 100%;
height: auto;
display: flex;
flex-wrap: wrap;
justify-content: stretch;
padding: 3px 13px;
img {
width: 82px;
height: 80px;
margin: 4px 0px 0px;
padding-right: 2px;
}
.dialog {
img {
width: 100%;
height: 100%;
margin: 0;
}
}
.el-carousel__item h3 {
color: #475669;
font-size: 18px;
opacity: 0.75;
line-height: 300px;
margin: 0;
height: 100%;
width: 100%;
}
.el-dialog__header {
display: none;
}
.el-dialog__body {
padding: 0 !important;
margin: 0 !important;
height: 460px;
background: #171717;
}
.el-carousel {
height: 100%;
}
.el-carousel__container {
height: 410px;
}
.el-carousel__indicators--outside {
margin-top: 20px;
}
}
</style>
上面是“vue项目如何结合swiper实现图片左右滑动切换”的全面内容,想了解更多关于 vuejs 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_3052.html
workflows工作流
文生图工作流:一幅海底睡莲,碧海蓝天comfyui工
一个穿着发光红色长袍的人
一只由水晶制成的蜂鸟
一个可爱的人形小机器人和一只蜗牛在森林
坐落在白雪覆盖的广阔平原上2只可爱的雪豹
一座巨大的野兽派建筑漂浮在热带风景中的贫民
一只黑色章鱼ComfyUI工作流
蝴蝶兰comfyui工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

js导出excel插件(兼容mac电脑Numbers表格)
SVG路径动画效果
制作一个好玩的倒计时
jquery鼠标滑过图片边框特效(jquery.focus-follow插件)
canvas经线动画走到效果
黑客入侵效果代码
css3结合svg做一个动态广告










