实现了图片列表展示的功能,一次性可查看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. asp.net mvc global.asax文件详解

    一.文件概述 global.asax这个文件包含全局应用程序事件的事件处理程序.它响应应用程序级别和会话级别事件的代码. 运行时, Global.asax 将被编译成一个动态生成的 .NET Fram ...

  2. Unity备份新知识待写

    Unity开发VR之Vuforia 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...

  3. jmeter 测试MD5加密登录接口

    1.点击options-funciton helper dialog,打开函数助手 在string to  calculate MD5 hash 中填写密码,复制function sysntax中的值 ...

  4. MVC中调用模态框之后导致JS失效

    今天在工作中碰到一个页面调用模态框之后,页面原来的JS失效的问题,由于前台经验较少,折腾了一天... 问题描述是这样,在页面,有两个下拉列表框A和B,做了下拉列表框联动,有一个button按钮会调用模 ...

  5. 学习笔记CB005:关键词、语料提取

    关键词提取.pynlpir库实现关键词提取. # coding:utf-8 import sys import importlib importlib.reload(sys) import pynlp ...

  6. expdp之include参数——实现表级别的expdp操作

    需求是这样的:想将A库的某schema中的一部分表导入到B库的某schema中. 第一可以想到的是使用expdp工具,但是如何只挑选某些表呢,通过查看官方文档,include参数可以实现该需求. in ...

  7. day62 中间件

    一.中间件的介绍 中间件顾名思义,是介于request与response处理之间的一道处理过程,相对比较轻量级, 并且在全局上改变django的输入与输出.因为改变的是全局,所以需要谨慎实用, 用不好 ...

  8. JS 实现Table相同行的单元格自动合并示例代码

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...

  9. layui layui.open弹窗后按enter键不停弹窗问题的解决

    问题描述:layui.open弹窗后,点击enter键会不停弹窗,背景颜色变得越来越深 解决办法:1.使用回调函数让按钮失去焦点 var info = layer.open({ type: 2 , t ...

  10. DB SQL Monitor 会话状态及等待事件监控工具

    DB SQL Monitor v1.7.6       Designed by Wang Zhaoguan   工具说明 --------------------------------------- ...