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>
    

      

  • 相关阅读:
    java网络编程客户端与服务端原理以及用URL解析HTTP协议
    java网络编程TCP传输—流操作—服务端反馈与客户端接收
    java网络编程TCP传输—流操作—拿到源后的写入动作
    用java网络编程中的TCP方式上传文本文件及出现的小问题
    关于session设置
    mencache
    打包
    反编译
    原型工具
    开源的jdbc
  • 原文地址:https://www.cnblogs.com/chenlw/p/9718887.html
Copyright © 2011-2022 走看看