顶部滑动导航菜单栏

参考:https://ext.dcloud.net.cn/plugin?id=738

  • template使用

<template>
	<view class="slidingMenu">
		<haverster-slidingMenu :list="list" :color="color" @changes="getIndex"></haverster-slidingMenu>
		<view class="contentList">
			<image :src="imageList[activeIndex]" mode=""></image>
		</view>
	</view>
</template>

  • JS
<script>
	import haversterSlidingMenu from '@/components/haverster-slidingMenu/haversterSlidingMenu.vue';
	export default {
		components: { haversterSlidingMenu },
		data() {
			return {
				list: ['男装', '母婴', '数码', '箱包', '生鲜', '食品', '饰品', '女装'], //默认传到顶部菜单栏的数据
				activeIndex: '0', ///菜单栏选中状态的index值
				color: 'white', //设置菜单的背景颜色
				imageList: [
					'http://pic1.win4000.com/mobile/2018-09-04/5b8dece4e565c.jpg',
					'https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=239553082,2832910159&fm=115&gp=0.jpg',
					'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2358570013,1985123782&fm=26&gp=0.jpg',
					'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=2914575322,940354749&fm=115&gp=0.jpg',
					'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3065463705,1034625646&fm=115&gp=0.jpg',
					'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=577097343,3406258596&fm=26&gp=0.jpg',
					"http://pic1.win4000.com/mobile/2018-09-04/5b8dece5b9dbe.jpg",
					"http://pic1.win4000.com/mobile/2018-09-04/5b8dece9ee511.jpg"
				],//下面图片显示
			};
		},
		onLoad() {},
		methods: {
			getIndex(e) {
				this.activeIndex = e;
			}
		}
	};
</script>

  • CSS

page{
		background-color: #FAFAFA;
	}
	.contentList {
		width: 750upx;
		height: 500px;
		margin-top: 20upx;
	}
	.contentList image {
		width: 100%;
		height: 100%;
	}
	.slidingMenu{
		
	}

  • 最后附上haversterSlidingMenu.vue

<template>
	<scroll-view class="uni-slidingMenu" scroll-x :style="{background: color}">
		<view  :class="['slidingMenuList',activeIndex==index?'active':'']" v-for="(item, index) in list" :key="index" @click="getActive(index)" v-cloak>{{ item }}</view>
	</scroll-view>
</template>

<script>
export default {
	name: 'uniSlidingMenu',
	props:{
		// 列表菜单
		list:{
			type: Array,
			// default:['首页1', '首页2', '首页3', '首页4', '首页4', '首页4', '首页4', '首页4']
		},
		color:{
			type:String,
			default:'#777777'
		}
		
	},
	data() {
		return {
			// list: ['首页1', '首页2', '首页3', '首页4', '首页4', '首页4', '首页4', '首页4'],
			activeIndex:"0"
		};
	},
	methods:{
		getActive(index){
			this.activeIndex=index;
			this.$emit("changes",this.activeIndex);
		}
	}
};
</script>

<style>
	page{
		background-color: #fafafa;
	}
/* 滑动菜单栏的总内容区域 */
.uni-slidingMenu {
	width: 100%;
	white-space: nowrap;
	height: 80rpx;
	background-color: #FFFFFF;
}
/* 循环显示的菜单栏 */
.slidingMenuList {
	height: 80rpx;
	line-height: 80rpx;
	display: inline-block;
	font-size: 24rpx;
	margin-left: 60rpx;
}
.slidingMenuList:last-child{
	margin-right: 60rpx;
}
/* 点击选中菜单栏时的样式 */
.active {
	color: pink;
	font-size: 28rpx;
	margin-left: 80rpx;
	border-bottom: 2rpx solid pink;
	box-sizing: border-box;
}
</style>


posted @ 2019-09-04 15:39  浪里小白龙呼呼呼  阅读(2388)  评论(2编辑  收藏  举报