zoukankan      html  css  js  c++  java
  • vue 的组件开发,以及swiper,axios的使用

    父组件
    <template> <div> <home-header :city="city"></home-header> //给子组件传递值 <home-swiper :list='swiperList'></home-swiper> <home-icons :icons="iconList"></home-icons> <home-recommend :list="recommendList"></home-recommend> <home-weekend :list="weekendList"></home-weekend> </div> </template> <script> import HomeHeader from './components/Header' import HomeSwiper from './components/Swiper' import HomeIcons from './components/Icons' import HomeRecommend from './components/Recommend' import HomeWeekend from './components/Weekend' import axios from 'axios' export default { name: 'Home', components: { HomeHeader, HomeSwiper, HomeIcons, HomeRecommend, HomeWeekend }, data (){ return { city:'', swiperList:[], iconList:[], recommendList:[], weekendList:[] } }, methods:{ getHomeInfo(){ axios.get('/api/index.json') .then(this.getHomeInfoSucc) }, getHomeInfoSucc(res){ res=res.data; if(res.res && res.data){ let data=res.data; this.city =data.city; this.swiperList = data.swiperList; this.iconList = data.iconList; this.recommendList = data.recommendList; this.weekendList = data.weekendList; } } }, mounted(){ this.getHomeInfo(); } } </script> <style> </style>

      子组件

    <template>
    	<div class="icons">
    		<swiper :options="swiperOption">//使用swiper插件
    			<swiper-slide  v-for="(page,index) of pages" :key="index">
    				<div class="icon" v-for="item of page"  :key="item.id">
    					<div class="iconImg" :key="item.id"   >
    						<img :src="item.imgUrl" class="icon-img-content">
    					</div>
    					<p class="icon-desc">{{item.desc}}</p>
    				</div>
    				
    			</swiper-slide>
    		</swiper>
    	</div>
    </template>
    
    <script>
    	export default {
    		name: 'HomeIcons',
    		props:{          //获取父组件传递的值
    			icons:Array
    		},
    		data (){
    			return {
    				swiperOption:{
    					autoplay:false
    				}
    			}
    		},
    		 computed: {
    		    pages () {
    		      const pages = []
    		      this.icons.forEach((item, index) => {
    		        const page = Math.floor(index / 8)
    		        if (!pages[page]) {
    		          pages[page] = []
    		        }
    		        pages[page].push(item)
    		      })
    		      return pages
    		    }
    		  }
    	}
    </script>
    
    <style lang="stylus" scoped>
    @import '~styles/varibles.styl' 
    	.icons{
    		height: 0;
    		padding-bottom: 50%;
    		overflow: hidden;
    		
    	}
    	.icon{
    		overflow: hidden;
    		height: 0;
    		 25%;
    		float: left;
    		padding-bottom: 25%;
    		position: relative;
    	}
    	.iconImg{
    		position: absolute;
    		top: 0;left: 0;right: 0;bottom: .44rem;
    		box-sizing: border-box;
    		padding:.05rem;
    	}
    	.icon-img-content{
    		display: block;
    		margin:0 auto;
    		height: 100%;
    	}
    	.icon-desc{
    		position: absolute;
    		left: 0;right: 0;bottom: 0;
    		height: .44rem;
    		line-height: .44rem;
    		color:$ftColor;
    		text-align: center;
    	}
    </style>
    

      

  • 相关阅读:
    你的程序够健壮么?我看未必。。。
    POJ 3415 Max Sum of Max-K-sub-sequence (线段树+dp思想)
    Android ARM汇编语言
    关于索引删除的策略IndexDeletionPolicy
    深度学习领域的一些大牛
    框架学习之道:PE框架简介
    PropertyPlaceholderConfigurer类的使用注意
    hdu 4622 Reincarnation (后缀自动机)
    总结showModalDialog在开发中的一些问题
    android端向服务器提交请求的几种方式
  • 原文地址:https://www.cnblogs.com/chenlw/p/9718887.html
Copyright © 2011-2022 走看看