uniapp——顶部导航栏(分段器)、带吸附效果顶部导航(下拉刷新,上拉加载更多,返回顶部)

1、顶部导航(支持左右滑,下拉刷新,上拉加载更多,返回顶部,加载动画)

在这里插入图片描述
需要用到的代码比较多,这里只提供下载地址:https://download.csdn.net/download/wy313622821/20106026

2、带吸附效果顶部导航(支持左右滑,下拉刷新,上拉加载更多,返回顶部,加载动画)

在这里插入图片描述
需要用到的代码比较多,这里只提供下载地址:https://download.csdn.net/download/wy313622821/20107287

3、顶部导航栏(分段器)

效果图:
在这里插入图片描述
在这里插入图片描述

segmented-control代码

<template>
	<view>
		<!-- style-type="'button'"中有 text和button两种风格 -->
		<view class="uni-padding-wrap ">
			<uni-segmented-control :current="currentItem" :values="items" :style-type="'text'" :active-color="'#007aff'"
			 @clickItem="onClickItem" />
		</view>

		<view class="content">
			<!-- 选项卡1的内容 -->
			<view v-if="currentItem === 0">
				<text class="content-text"> 选项卡1的内容</text>
			</view>
			<!-- 选项卡2的内容 -->
			<view v-if="currentItem === 1">
				<text class="content-text">选项卡2的内容</text>
			</view>
			<!-- 选项卡3的内容 -->
			<view v-if="currentItem === 2">
				<text class="content-text">选项卡3的内容</text>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: ['选项卡1', '选项卡2', '选项卡3'],
				currentItem: 0,
			}
		},
		methods: {
			onClickItem(e) {
				if (this.currentItem !== e.currentIndex) {
					this.currentItem = e.currentIndex
				}
			},
		}
	}
</script>

<style>
	/* 头条小程序组件内不能引入字体 */
	/* #ifdef MP-TOUTIAO */
	@font-face {
		font-family: uniicons;
		font-weight: normal;
		font-style: normal;
		src: url('~@/static/uni.ttf') format('truetype');
	}

	/* #endif */

	/* #ifndef APP-NVUE */
	page {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		background-color: #efeff4;
		min-height: 100%;
		height: auto;
	}

	.uni-padding-wrap {
		width: 750rpx;
		padding: 0px 30px;
	}

	.content {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
		height: 150px;
		text-align: center;
	}

	.content-text {
		font-size: 18px;
		color: #333;
	}
	/* #endif */
</style>

uni-segmented-control代码

<template>
	<view :class="[styleType === 'text'?'segmented-control--text' : 'segmented-control--button' ]" :style="{ borderColor: styleType === 'text' ? '' : activeColor }"
	 class="segmented-control">
		<view v-for="(item, index) in values" :class="[ styleType === 'text'?'segmented-control__item--text': 'segmented-control__item--button' , index === currentIndex&&styleType === 'button'?'segmented-control__item--button--active': '' , index === 0&&styleType === 'button'?'segmented-control__item--button--first': '',index === values.length - 1&&styleType === 'button'?'segmented-control__item--button--last': '' ]"
		 :key="index" :style="{
        backgroundColor: index === currentIndex && styleType === 'button' ? activeColor : '',borderColor: index === currentIndex&&styleType === 'text'||styleType === 'button'?activeColor:'transparent'
      }"
		 class="segmented-control__item" @click="_onClick(index)">
			<text :style="{color:
          index === currentIndex
            ? styleType === 'text'
              ? activeColor
              : '#fff'
            : styleType === 'text'
              ? '#000'
              : activeColor}"
			 class="segmented-control__text">{{ item }}</text>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'UniSegmentedControl',
		props: {
			current: {
				type: Number,
				default: 0
			},
			values: {
				type: Array,
				default () {
					return []
				}
			},
			activeColor: {
				type: String,
				default: '#007aff'
			},
			styleType: {
				type: String,
				default: 'button'
			}
		},
		data() {
			return {
				currentIndex: 0
			}
		},
		watch: {
			current(val) {
				if (val !== this.currentIndex) {
					this.currentIndex = val
				}
			}
		},
		created() {
			this.currentIndex = this.current
		},
		methods: {
			_onClick(index) {
				if (this.currentIndex !== index) {
					this.currentIndex = index
					this.$emit('clickItem', {currentIndex:index})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/uni.scss';

	.segmented-control {
		/* #ifndef APP-NVUE */
		display: flex;
		box-sizing: border-box;
		/* #endif */
		flex-direction: row;
		height: 36px;
		overflow: hidden;
	}

	.segmented-control__item {
		/* #ifndef APP-NVUE */
		display: inline-flex;
		box-sizing: border-box;
		/* #endif */
		position: relative;
		flex: 1;
		justify-content: center;
		align-items: center;
	}

	.segmented-control__item--button {
		border-style: solid;
		border-top-width: 1px;
		border-bottom-width: 1px;
		border-right-width: 1px;
		border-left-width: 0;
	}

	.segmented-control__item--button--first {
		border-left-width: 1px;
		border-top-left-radius: 5px;
		border-bottom-left-radius: 5px;
	}

	.segmented-control__item--button--last {
		border-top-right-radius: 5px;
		border-bottom-right-radius: 5px;
	}

	.segmented-control__item--text {
		border-bottom-style: solid;
		border-bottom-width: 3px;
	}

	.segmented-control__text {
		font-size: 16px;
		line-height: 20px;
		text-align: center;
	}
</style>

  • 6
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
如果你想通过 uView 分段来改变折线图,可以考虑使用 Vue.js 的数据绑定和计算属性来实现。 首先,你需要定义一个变量来保存分段的选项值,例如: ``` <template> <view> <u-segmented-control v-model="selected"> <u-segmented-control-item title="选项1"></u-segmented-control-item> <u-segmented-control-item title="选项2"></u-segmented-control-item> <u-segmented-control-item title="选项3"></u-segmented-control-item> </u-segmented-control> <u-line-chart :data="chartData"></u-line-chart> </view> </template> <script> export default { data() { return { selected: 0, // 默认选中第一个选项 chartData: { // 折线图数据 } } }, computed: { filteredData() { // 根据选项值筛选折线图数据 // 例如,当 selected 为 0 时,返回原始数据;当 selected 为 1 时,返回经过处理后的数据 if (this.selected === 0) { return this.chartData } else if (this.selected === 1) { // 处理数据 return processedData } else if (this.selected === 2) { // 处理数据 return processedData2 } } } } </script> ``` 在上面的代码中,我们定义了一个 `selected` 变量来保存分段的选项值,然后使用 `v-model` 指令将其绑定到分段上。当用户改变选项时,`selected` 变量的值也会随之改变。 然后,我们使用计算属性 `filteredData` 来根据 `selected` 变量的值筛选折线图数据。例如,当 `selected` 为 0 时,返回原始数据;当 `selected` 为 1 时,返回经过处理后的数据。 最后,在折线图组件中使用 `filteredData` 来渲染图表。 当用户改变分段的选项时,`filteredData` 会自动新,从而改变折线图的显示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wy313622821

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值