Vue 头部动态添加数据

上篇文章 我们已经完成了头部和中间部分的骨架搭建,现在我们来开发头部的css代码吧



第一步 连接data.json获得图片以及品牌名称及基础数据

在header.vue 中template中写入


这样就可以获取到商铺图片。

我们可以去data.json文件中看看seller.avatar 


 "avatar": "http://static.galileo.xiaojukeji.com/static/tms/default_header.png",是这样的

第二步获取商铺名称


我们可以去data.json文件中看看seller.name

 "name": "粥品香坊(回龙观)",

第三步 获取配送时间


第四步 获取在线减满


第五步获取介绍


补:获取长度

<div class="mui_position"@click="showDeta">
			<span class="count">{{seller.supports.length}}个</span>
			<span class="icc"><img src="../img/right.png"></span>
		</div>

第六步 编写css

<style>
	.header{
		position: relative;
	}
	.mui-content{
		background: none;
		opacity: 0.;
	
	    font-size: 13px;
	    line-height: 22px;
	    color: white;
	}
	.name{
		font-size: 15px;
	}
	.avatar{
		display: inline-block;
	   
		
	}
	.avatar img{
		float: right;
		margin-right: 15px;
	}
	.mui-padding{
			padding: 24px 12px 10px 24px;
	}
	.bullent{
		display: inline-block;
		position: relative;
		
	}
	.text{
		display: inline-block;
		margin-left: 15px;	}
	.brand{
		display: inline-block;
		width: 30px;
		height: 18px;
		position:relative;
	}
	.brand img{
		width: 30px;
		height: 18px;
		position: absolute;
		top: 4px;
	}
	.icon{
		display: inline-block;
		height: 18px;
		
	
	}
	.support{
	position: relative;	
	}
	.support span img{
		height: 18px;
		position: absolute;
		top: 4px;
	}
	.mui_position{
		position: absolute;
		width: 60px;
		height: 30px;
		background:rgba(7,17,27,0.2);
		border-radius:15px;
		text-align: center;
		top: 40px;
		right: 15px;
		line-height: 30px;
	}
	.count{
		
		color: #CCCCCC;
	}
	.icc img{
		vertical-align: middle;
		margin-top: -5px;
	}
	.bullent-conten{
		width: 100%;
		height: 30px;
		background:rgba(7,17,27,0.2);
		font-size: 13px;
		
	}
	.bullent-title{
		display: inline-block;
		float: left;
		
	}
	.bullent-title img{
		height: 18px;
	  margin-top: 5px;
	  margin-left: 20px;
	}
	.bullen-text{
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		display: inline-block;
	line-height: 30px;
	color: white;
		
	}
	.mui-col-xs-1 img{
		margin-top: 5px;
		margin-left: 20%;
	}
	.bullent-img{display: inline-block;}
	.bacground{
		width: 100%;
		height: 100%;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -1;
		background: rgba(7,17,27,0.5);
		filter: blur(10px);
		
	}
	.mask{
		position: fixed;
		top: 0;
		left: 0;
		background: rgba(7,17,27,0.5);
		width: 100%;
		height: 100%;
		z-index: 100;
		
	}
	.mask_warpp{
	min-height: 100%;
	
		
	}
	.mask_main{
		margin-top: 64px;
		padding-bottom: 64px;
	}
	.mask_icon{
		position: relative;
		width: 32px;
		height: 32px;
		margin:-64px auto 0 auto;
		clear: both;
		font-size: 32px;
	}
	.clearfix{
		display: inline-block;
	}
	.clearfix:after{
		content: ".";
		display: block;
		height: 0;
		line-height: 0;
		clear: both;
		visibility: hidden;
	}
	
</style>


在来看看整体的header.vue

<template>
	<div class="header">
		<div class="mui-content">
			<div class="mui-row mui-padding">
		<div class="avatar mui-col-sm-3 mui-col-xs-3">
		<img width="64" height="64" :src="seller.avatar" />
		</div>
		<div class="bullent mui-col-sm-9  mui-col-xs-9">
			 <div class="title">
			 	<span class="brand"><img src="../img/brand@2x.png"></span>
			 	<span class="name">{{seller.name}}</span>
			 </div>
		
		<div class="description">
			{{seller.description}}/{{seller.deliveryTime}}分钟送达
			
		</div>
		<div class="support" v-if="seller.supports" style="width: 50%;">
			<span class="icon"><img src="../img/decrease_3@2x.png"></span>
			<span class="text">{{seller.supports[0].description}}</span>
			
		</div>
		<div v-if="seller.supports">
		<div class="mui_position"@click="showDeta">
			<span class="count">{{seller.supports.length}}个</span>
			<span class="icc"><img src="../img/right.png"></span>
		</div>
		</div>
		
		
			 </div>
			 
		</div>
		
		
		</div>
		<div class="bullent-conten"@click="showDeta">
			 	     <div class="mui-row">
			 		<span class="bullent-title mui-col-sm-2 mui-col-xs-2"><img src="../img/bulletin@2x.png"></span>
			 		<span class="bullen-text mui-col-sm-9 mui-col-xs-9" >{{seller.bulletin}}</span>
			 		<span class="bullent-img  mui-col-sm-1 mui-col-xs-1" ><img src="../img/right.png" ></span>
			 
			 	</div>
			 </div>
			  <div class="bacground">
			 <img :src="seller.avatar"width="100%" height="100%"/>
			 </div>
			<div class="mask" v-show="detaShow">
				<div class="mask_warpp clearfix">
					<div class="mask_main">
					
						
						
						
					</div>
				</div>
				<div class="mask_icon" @click="showClone()" >
					<img src="../img/guanbi.png" />
				</div>
				
			</div>
	</div>
	
</template>

<script type="text/ecmascript-6">
	export default {
		props:{
			seller:{
				type:Object
			}
		},
		data(){
			return{
				detaShow:false,
				
			};
		},
		methods:{
			showDeta(){
				this.detaShow=true;
			},
		  showClone(){
		  	this.detaShow=false
		  }
		},
		
	};
</script>
<style>
	@import url("/static/mui.min.css");
</style>
<style>
	.header{
		position: relative;
	}
	.mui-content{
		background: none;
		opacity: 0.;
	
	    font-size: 13px;
	    line-height: 22px;
	    color: white;
	}
	.name{
		font-size: 15px;
	}
	.avatar{
		display: inline-block;
	   
		
	}
	.avatar img{
		float: right;
		margin-right: 15px;
	}
	.mui-padding{
			padding: 24px 12px 10px 24px;
	}
	.bullent{
		display: inline-block;
		position: relative;
		
	}
	.text{
		display: inline-block;
		margin-left: 15px;	}
	.brand{
		display: inline-block;
		width: 30px;
		height: 18px;
		position:relative;
	}
	.brand img{
		width: 30px;
		height: 18px;
		position: absolute;
		top: 4px;
	}
	.icon{
		display: inline-block;
		height: 18px;
		
	
	}
	.support{
	position: relative;	
	}
	.support span img{
		height: 18px;
		position: absolute;
		top: 4px;
	}
	.mui_position{
		position: absolute;
		width: 60px;
		height: 30px;
		background:rgba(7,17,27,0.2);
		border-radius:15px;
		text-align: center;
		top: 40px;
		right: 15px;
		line-height: 30px;
	}
	.count{
		
		color: #CCCCCC;
	}
	.icc img{
		vertical-align: middle;
		margin-top: -5px;
	}
	.bullent-conten{
		width: 100%;
		height: 30px;
		background:rgba(7,17,27,0.2);
		font-size: 13px;
		
	}
	.bullent-title{
		display: inline-block;
		float: left;
		
	}
	.bullent-title img{
		height: 18px;
	  margin-top: 5px;
	  margin-left: 20px;
	}
	.bullen-text{
		text-overflow: ellipsis;
		overflow: hidden;
		white-space: nowrap;
		display: inline-block;
	line-height: 30px;
	color: white;
		
	}
	.mui-col-xs-1 img{
		margin-top: 5px;
		margin-left: 20%;
	}
	.bullent-img{display: inline-block;}
	.bacground{
		width: 100%;
		height: 100%;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -1;
		background: rgba(7,17,27,0.5);
		filter: blur(10px);
		
	}
	.mask{
		position: fixed;
		top: 0;
		left: 0;
		background: rgba(7,17,27,0.5);
		width: 100%;
		height: 100%;
		z-index: 100;
		
	}
	.mask_warpp{
	min-height: 100%;
	
		
	}
	.mask_main{
		margin-top: 64px;
		padding-bottom: 64px;
	}
	.mask_icon{
		position: relative;
		width: 32px;
		height: 32px;
		margin:-64px auto 0 auto;
		clear: both;
		font-size: 32px;
	}
	.clearfix{
		display: inline-block;
	}
	.clearfix:after{
		content: ".";
		display: block;
		height: 0;
		line-height: 0;
		clear: both;
		visibility: hidden;
	}
	
</style>


这样头部就已经完成了 


### 使用 `transition-group` 组件实现在列表头部添加数据时带有的动画效果 为了在 Vue 应用程序中实现当向列表头部添加数据时带有动画效果的功能,可以利用 `<transition-group>` 组件。此组件允许为列表项定义进入和离开的过渡效果[^1]。 #### HTML 结构与模板 首先,在HTML结构上,需要确保有一个容器用于渲染列表项目,并且该容器被包裹在一个 `<transition-group>` 标签内: ```html <ul> <transition-group name="list-complete"> <li v-for="(item, index) in items" :key="index">{{ item }}</li> </transition-group> </ul> <button @click="addItem">Add Item to Head</button> ``` 这段代码展示了如何通过点击按钮触发函数 `addItem()` 来往数组 `items` 的开头位置插入新的条目,从而模拟向列表添加元素的行为[^2]。 #### JavaScript 部分 接着是在JavaScript部分处理逻辑的地方,这里假设已经初始化了一个名为 `items` 的响应式属性用来存储要显示的数据集合;以及一个方法 `addItem` 被绑定到按钮上的事件监听器,每当调用它就会执行一次操作——即把一个新的字符串加到 `items` 数组最前面的位置上去: ```javascript new Vue({ el: '#app', data() { return { items: ['Item A', 'Item B'] } }, methods: { addItem() { this.items.unshift('New Item'); } } }) ``` 上述脚本片段中的 `.unshift()` 方法会将指定的新成员放置于现有项目的之前,因此每次都会更新视图并触发动画过程[^3]。 #### CSS 过渡样式 最后一步就是编写CSS类来控制具体的视觉变化方式。对于每一个加入或移除的动作都应有对应的样式规则去描述其行为特性。以下是针对上面例子所设计的一套简单的过渡效果: ```css .list-complete-enter-active, .list-complete-leave-active { transition: all .5s ease; } .list-complete-enter-from, .list-complete-leave-to /* .list-complete-leave-active below version 2.1.8 */ { opacity: 0; transform: translateY(30px); } /* 确保移动其他元素 */ .list-complete-move { transition: transform .5s; } ``` 这些样式设置了新增加的节点从下方淡入的同时向上滑动到位,而即将消失的节点则相反地向下退场直至完全透明化[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值