实现了图片列表展示的功能,一次性可查看4张图,可向左向右点击查看,代码如下:

index.vue:

<template>
<div class="content-container">
<div class="content-container-item content">
<!-- 使用transition加过渡效果 -->
<transition-group tag="div" class="content-inner" name="list" mode="out-in">
<!-- 图片列表封装成组件,以便扩展 -->
<pic-list v-for="item in showPicList" :key="item.code" :picItem="item.picList"></pic-list>
</transition-group>
</div>
<!-- 向左点击查看图片按钮 -->
<div class="content-container-item icon-container left-icon-container">
<div @click="prevStation" class="shuffling-btn prev"></div>
</div>
<!-- 向右点击查看图片按钮 -->
<div class="content-container-item icon-container right-icon-container">
<div @click="nextStation" class="shuffling-btn next"></div>
</div>
</div>
</template> <script>
import picList from './pic-list';
export default {
name: 'pictureContainer',
data() {
return {
showPicList: [{
code: 1,
picList: './1.jpg'
},
{
code: 2,
picList: './2.jpg'
},
{
code: 3,
picList: './3.jpg'
},
{
code: 4,
picList: './4.jpg'
},
{
code: 5,
picList: './5.jpg'
},
{
code: 6,
picList: './6.jpg'
},
{
code: 7,
picList: './7.jpg'
},
{
code: 8,
picList: './8.jpg'
}],
watchList: [], //图片列表list
showListIndex: 0, //当前页面显示的第一个图片列表在watchList中的位置
}
},
components: {
picList
},
mounted() {
//加载图片列表
this.getWatchList();
},
methods: {
/**
* @description 获取可视范围图片列表
*/
getWatchList() {
this.watchList = this.showPicList;
if(this.watchList.length <= 4) {
this.showPicList = this.watchList;
} else {
this.showPicList = this.watchList.slice(0, 4);
}
},
/**
* @description 向右点击事件
*/
nextStation() {
if((this.showListIndex + 4) < this.watchList.length) {
this.showPicList = this.watchList.slice(++this.showListIndex, this.showListIndex + 4);
} else {
utils.showAlert('右侧已无数据');
}
},
/**
* @description 向左点击事件
*/
prevStation() {
if(this.showListIndex > 0) {
this.showPicList = this.watchList.slice(--this.showListIndex, this.showListIndex + 4);
} else {
utils.showAlert('左侧已无数据');
}
}
}
}
</script> <style scoped lang="less">
@icon-container-width: .3rem;
@title-background: #35393E; .content-container {
width: 100%;
height: 1.3rem;
background: @title-background;
.icon-container {
width: @icon-container-width;
max-width: @icon-container-width;
}
.left-icon-container {
margin-left: -100%;
}
.right-icon-container {
margin-left: @icon-container-width;
&:after {
display: block;
content: '';
clear: both;
height: 0;
line-height: 0;
visibility: hidden;
}
}
.content-container-item {
float: left;
height: 100%;
position: relative;
.shuffling-btn {
position: absolute;
top: 50%;
left: 50%;
margin-left: -.25rem;
margin-top: -.25rem;
cursor: pointer;
width: .5rem;
height: .5rem;
border-radius: .5rem;
}
.prev {
background: url(./prev.png) no-repeat;
}
.next {
background: url(./next.png) no-repeat;
}
}
.content {
width: 100%;
}
.content-inner {
margin: 0 @icon-container-width;
display: flex;
flex-wrap: nowrap;
align-items: center;
height: 100%;
justify-content: center;
.list-enter-active, .list-leave-active {
transition: opacity 2s ease-in-out;
}
.list-leave, .list-enter {
opacity: 0;
}
}
}
</style>

子组件 pic-list.vue:

<template>
<div class="main" @click.stop="clickItem(item)">
<div :style="{backgroundImage: 'url(' + item + ')'}"></div>
</div>
</template> <script type="text/ecmascript-6">
/**
* @description 图片列表切换子组件,传递单个item即可
*/ export default {
name: 'picList',
props: {
item: {
type: Object,
default: () => ({})
}
},
methods: {
/**
* @description 点击图片列表事件
*/
clickItem(item) {
this.$emit('showPicture', item);
}
}
}
</script> <style scoped lang="less">
@base-line-height: .4rem;
@item-background-color: #303438; .main {
margin: 2% .1rem;
width: 25%;
min-width: 1rem;
height: 1rem;
color: @item-background-color; &>div {
width: 100%;
height: 100%;
background-size: 100%;
background-repeat: no-repeat;
}
}
</style>

Vue 封装可向左向右查看图片列表的组件的更多相关文章

  1. 封装实现UIButton左文字右图片

    #import "TitleButton.h" @implementation TitleButton - (instancetype)initWithFrame:(CGRect) ...

  2. js实现图片加载特效(从左到右,百叶窗,从中间到两边)

    /* 网上百度的,感觉”从中间到两边“的效果写的不是很好,改了一下,感觉可以了!*/<html> <head> <title></title> < ...

  3. vue封装一个简单的div框选时间的组件

    记录一下我前段时间封装的一个vue组件吧.技术需要积累,有时间我把我之前写的还不错的组件都开源出来.并尝试vue和react 两种方式的组件封装.今天简单写下鼠标框选div选中效果的封装吧. div框 ...

  4. css3动画 一行字鼠标触发 hover 从左到右颜色渐变

    偶然的机会发现的这个东东 这几天做公司的官网 老板突然说出了一个外国网站 我就顺手搜了 并没有发现他说的高科技 但是一个东西深深地吸引了我 就是我下面要说的动画  这个好像不能放视频 我就简单的描述一 ...

  5. centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标前所有字符 Ctrl+r 搜索命 hash命令 Ctrl+左箭头/右箭头 cd命令 第三节课

    centos 目录结构 快捷键 ls命令,alias别名,so:动态库 a:静态库,环境变量PATH,Ctrl+z 暂停命令,Ctrl+a 光标到行首,Ctrl+e 光标到行尾,Ctrl+u 删除光标 ...

  6. Vue 监听鼠标左键 鼠标右键以及鼠标中键修饰符click.left&contextmenu&click.middle

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 【代码笔记】iOS-可以向左(右)滑动

    一,效果图. 二,代码. RootViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional se ...

  8. c++ 左值右值 函数模板

    1.先看一段代码,这就是一种函数模板的用法,但是红色的部分如果把a写成a++或者写成一个常量比如1,都是编译不过的,因为如果是a++的话,实际上首先是取得a的 值0,而0作为一个常量没有地址.写成1也 ...

  9. 剑指offer系列——二维数组中,每行从左到右递增,每列从上到下递增,设计算法找其中的一个数

    题目:二维数组中,每行从左到右递增,每列从上到下递增,设计一个算法,找其中的一个数 分析: 二维数组这里把它看作一个矩形结构,如图所示: 1 2 8 2 4 9 12 4 7 10 13 6 8 11 ...

随机推荐

  1. AI之旅(2):初识线性回归

    前置知识   矩阵.求导 知识地图   学习一个新事物之前,先问两个问题,我在哪里?我要去哪里?这两个问题可以避免我们迷失在知识的海洋里,所以在开始之前先看看地图.   此前我们已经为了解线性回归做了 ...

  2. Shell脚本中的逻辑判断、文件目录属性判断、if的特殊用法、case判断

    1.Shell脚本中的逻辑判断 格式1:if 条件 ; then 语句; fi格式2:if 条件; then 语句; else 语句; fi格式3:if …; then … ;elif …; then ...

  3. 不同组的id列表的汇总对比

    需求: 三个不同的dfs中存在不同的多个节点id,现在需要求出不同的dfs之间的节点对应关系,比如,哪些节点在某一个dfs,但是不在另一个dfs中 思路: 一. 如果是单纯计算dfs中节点数量,则可以 ...

  4. ms16-032漏洞复现过程

    这章节写的是ms16-032漏洞,这个漏洞是16年发布的,版本对象是03.08和12.文章即自己的笔记嘛,既然学了就写下来.在写完这个漏洞后明天就该认真刷题针对16号的比赛了.Over,让我们开始吧! ...

  5. hdu 1698 (延迟标记+区间修改+区间求和)

    In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...

  6. win10蓝屏,windbg的使用

    win10蓝屏,windbg的使用 上微软官网下载windbg https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/d ...

  7. 手机响应式echarts

    // 基于准备好的dom,初始化echarts实例var myChart = echarts.init(document.getElementById('main'));// 使用刚指定的配置项和数据 ...

  8. iOS launchImage

    iOS launchImage https://stackoverflow.com/questions/34027270/ios-launch-screen-in-react-native 如何设置: ...

  9. Django学习笔记之视图高级-CSV文件生成

    生成CSV文件 有时候我们做的网站,需要将一些数据,生成有一个CSV文件给浏览器,并且是作为附件的形式下载下来.以下将讲解如何生成CSV文件. 生成小的CSV文件 这里将用一个生成小的CSV文件为例. ...

  10. 关于使用easyui 中提示dialog is not a function的问题

    我们经常在一些项目使用easyui,当然必不可少都会用到dialog这个功能,但是有时候你会发现: 明明我的代码没有错误,调用的规范按照API的来撰写,但是还有会报 $(...).dialog is ...