uniapp点击导航栏,显示页面(动态渲染)

1.效果图展示(点击有效果且显示不同页面)

2. hrml代码   tab_itmbot所属标签表示下划线

              <view class="tab">
					<view :class="activeone"  @click="chenked(1)">
						<view class="tab_itemtitle">全部</view>
						<view class="tab_itembot"></view>
					</view>
					<view :class="activetwo"  @click="chenked(2)">
						<view class="tab_itemtitle" >待支付</view>
						<view class="tab_itembot"></view>
					</view>
					<view :class="activethree"  @click="chenked(3)">
						<view class="tab_itemtitle" >待发货</view>
						<view class="tab_itembot"></view>
					</view>
					<view :class="activefour"  @click="chenked(4)">
						<view class="tab_itemtitle">已发货</view>
						<view class="tab_itembot"></view>
					</view>
					<view :class="activefive"  @click="chenked(5)">
						<view class="tab_itemtitle" >已完成</view>
						<view class="tab_itembot"></view>
					</view>
				</view>

3.js代码  

包括组件引入,注册

注意:在conponents里面注册时,命名必须用小驼峰注册法:

即当标识符是一个单词的时候首字母小写

    当标识符是多个单词的时候首字母小写,其他单词首字母大写

<script>
	import pagea from "@/components/pageone/pageone.vue"
	import pageb from "@/components/pagetwo/pagetwo.vue"
	import pagec from "@/components/pagethree/pagethree.vue"
	import paged from "@/components/pagefour/pagefour.vue"
	import pagee from "@/components/pagefive/pagefive.vue"
	export default {
		components:{
			pagea,
			pageb,
			pagec,
			paged,
			pagee
		},
		data() {
			return {
				isActive: 1
			};
		},
		computed:{
				activeone() {
							return this.isActive==1?'active':'activeone'
						},                                          
			    activetwo() {                                         
							return this.isActive==2?'active':'activeone'
						},                                          
			    activethree() {                                         
							return this.isActive==3?'active':'activeone'
						},                                          
			    activefour() {                                         
							return this.isActive==4?'active':'activeone'
						},                                          
				activefive() {                                         
							return this.isActive==5?'active':'activeone'
						},
		},
		methods: {
					chenked(type) {
									this.isActive = type
								}
					}
		
	}
</script>

4.scss代码,注意要使用scss的页面

<style lang="scss">

	.tab {
			display: flex;
			width: 750rpx;
			align-items: center;
			height: 100rpx;
			background-color: #fff;
			// 选中的样式
			.active {
				height:50px;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-left: 50rpx;
				margin-top: 40rpx;
				.tab_itemtitle {
					text-align: center;
					height: 48rpx;
					font-size: 34rpx;
					font-weight: bold;
					color: #EE2747;
					line-height: 40rpx;
				}
				.tab_itembot {
					width: 43rpx;
					height: 6rpx;
					background: #EE2747;
					border-radius: 5rpx;
					margin-top: 5rpx;
				}
			}
			// 未选中的样式
			.activeone{
				height:50px ;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-left: 50rpx;
				margin-top: 40rpx;
				.tab_itemtitle {
				    height: 45rpx;
				    font-size: 33rpx;
				    font-weight: 500;
				    color: #666;
				    line-height: 38rpx;
					text-align: center;
				}
				
			}
			
		}

</style>

5.使用组件(组件里面写页面的具体内容)

<pagea v-if="isActive==1"></pagea>
<pageb v-if="isActive==2"></pageb>
<pagec v-if="isActive==3"></pagec>
<paged v-if="isActive==4"></paged>
<pagee v-if="isActive==5"></pagee>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Uniapp中实现底部导航栏点击动画,你可以按照以下步骤进行操作: 1. 在页面中创建底部导航栏的布局。可以使用`uni-tabbar`组件来实现,其中每个导航项使用`uni-tabbar-item`组件。 2. 在Vue实例或组件的data中定义一个变量,用于保存当前选中的导航项索引。例如,你可以将其命名为`activeIndex`。 3. 在每个导航项的`uni-tabbar-item`组件中,绑定一个点击事件监听器,并在事件处理函数中更新`activeIndex`的值。 4. 使用条件渲染(v-if或v-bind)来根据`activeIndex`的值来动态添加选中状态的样式。 5. 可以使用CSS过渡或动画效果来实现点击动画。例如,在选中状态下,可以添加一个过渡效果或修改样式属性来实现动画效果。 这是一个简单的示例代码: ```html <template> <div> <uni-tabbar> <uni-tabbar-item icon="home" text="首页" @click="handleClick(0)" :selected="activeIndex === 0"></uni-tabbar-item> <uni-tabbar-item icon="message" text="消息" @click="handleClick(1)" :selected="activeIndex === 1"></uni-tabbar-item> <uni-tabbar-item icon="user" text="我的" @click="handleClick(2)" :selected="activeIndex === 2"></uni-tabbar-item> </uni-tabbar> </div> </template> <script> export default { data() { return { activeIndex: 0 }; }, methods: { handleClick(index) { this.activeIndex = index; } } }; </script> <style scoped> /* 添加选中状态的样式 */ .uni-tabbar-item[selected] { /* 选中状态下的样式 */ } </style> ``` 在上述示例中,我们使用了`uni-tabbar`和`uni-tabbar-item`组件来创建底部导航栏,并绑定了点击事件`@click`。在点击事件的处理函数中,我们更新了`activeIndex`的值,并通过条件渲染来添加选中状态的样式。你可以根据自己的需求自定义样式和动画效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值