当前位置: 首页 > news >正文

uniapp的拨打电话,下拉和上划

一.拨打电话---------- uni.makePhoneCall

代码:

<view class="" @click="phone">
				联系电话: 1111111111111
</view>
	phone() {
				uni.makePhoneCall({
					phoneNumber: '111111' //拨打电话
				})
			}

二.下拉加载更多------onReachBottom

代码:

<template>
	<view class="goods_list">
		<goodList @goodsItemClicjk='goD' :goods='goods' />
		<view class="isOver" style="text-align: center;" v-if="flag">
			-----我是有底线的
		</view>
	</view>
</template>

<script>
	import goodList from "../../components/goods_list.vue"
	export default {
		data() {
			return {
				pageindex: 1,
				goods: [],
				flag: false
			}
		},
		components: {
			goodList
		},
		onLoad() {
			this.getGoodList()
		},
		methods: {
			async getGoodList(callback) {
				const res = await this.$myRequest({
					url: '/api/getgoods?pageindex=' + this.pageindex
				})
				console.log(res)
				this.goods = [...this.goods, ...res.data.message]
				callback && callback()
			}
		},

		// 下拉下载更多
		onReachBottom() {
			// 通过和总的数据进行比较
			if (this.goods.length < this.pageindex * 10) return this.flag = true
			// 获取第二页数据
			this.pageindex++
			this.getGoodList()

		},
		onPullDownRefresh() {
			// 下拉刷新

			this.pageindex = 1 //
			this.goods = []
			this.flag = false //
			// this.getGoodList()
			setTimeout(() => {
				this.getGoodList(() => {
					uni.stopPullDownRefresh()
				})
			}, 1000)

		}

	}
</script>

<style lang="scss">
	.goods_list {
		background: #eee;
	}
</style>

代码分析:

(1)在pages.json里面开启 "enablePullDownRefresh": true。

(2):通过v-if来控制-----我是有底线的显示和影藏

代码:

 上方可以看到。

触发的时间:

	// 下拉下载更多
		onReachBottom() {
			// 通过和总的数据进行比较
			if (this.goods.length < this.pageindex * 10) return this.flag = true
			// 获取第二页数据
			this.pageindex++
			this.getGoodList()

		},

每次触底都会加载下一页的数据。

怎么判断数据没有了呢?

通常情况接口会返回一个total给你,

当然我这个页面没返回

this.goods.length //渲染的总数据

total  //总的数据

如果两者相等如果数据已经全部请求过来了。

找个时候是应该站出来表明自己的观点。

将flag的值变为true。

(3)默认请求第一页的数据,页数数据合并的处理

	onLoad() {
			this.getGoodList()
		},
		methods: {
			async getGoodList(callback) {
				const res = await this.$myRequest({
					url: '/api/getgoods?pageindex=' + this.pageindex
				})
				console.log(res)
				this.goods = [...this.goods, ...res.data.message]
				callback && callback()
			}
		},

代码分析:

goods: []   //是要循环的数据

this.goods = [...this.goods, ...res.data.message]。

这段代码换种写法:

	this.goods = res.data.message

这可以理解将下请求过来的数据直接赋值第一个页的数据。

当触底的时候:

代码:

	onReachBottom() {
			// 获取第二页数据
			this.pageindex++
			this.getGoodList()
		},

此时 this.pageindex++的值变为2,获取第二页的数据。

第一页的数据:

第二页的数据:

 此时只会显示5条

 得到的结果是重新覆盖了。

我们想要的肯定是第一页第二页都要。

解决方法:

	this.goods = [...this.goods, ...res.data.message]

三.下拉刷新------------onPullDownRefresh

代码:

onPullDownRefresh() {
			// 下拉刷新

			this.pageindex = 1 //
			this.goods = []
			this.flag = false //
			// this.getGoodList()
			setTimeout(() => {
				this.getGoodList(() => {
					uni.stopPullDownRefresh()
				})
			}, 1000)

		}

1.回到第一页

2.将渲染的数据置空

3.关闭我是有底线

4.uni.stopPullDownRefresh()

关闭下拉的时候的转圈。

四.二级联动

代码:

<template>
	<view class="pics">
		<!-- n能够滚动的区域 -->
		<!-- n能够滚动的区域 -->
		<!-- scroll-y="true" 纵向滚动 -->
		<scroll-view scroll-y="true" class="left">
			<view :class="active===index?'active':'' " v-for="(item,index) in cates" :key='item.id'
				@click="leftClick(index,item.id)">{{item.title}}</view>

		</scroll-view>
		<scroll-view scroll-y="true"  class="right">
			<view class="item" v-for="item in secondData" :key='item.id'>
				<image  @click="previeImg(item.img_url)" :src="item.img_url" mode=""></image>
				<text>{{item.title}}</text>
			</view>
			<!-- //暂无数据的处理 -->
			<text v-if="secondData.length===0">暂无数据</text>
			
		</scroll-view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				cates: [],
				active: 0,
				secondData: []
			}
		},
		onLoad() {
			this.getPicsState()
		},
		methods: {
			// 图片的预览
			previeImg(current){
				const urls=this.secondData.map(item=>{
					return item.img_url  //返回每一项的地址
				})
				uni.previewImage({
					current,
					urls
				})
			},
			async leftClick(index, id) {
				this.active = index
				const res = await this.$myRequest({
					url: '/api/getimages/' + id //接口地址
				})
				this.secondData = res.data.message
				
			},
			async getPicsState() {
				const res = await this.$myRequest({
					url: '/api/getimgcategory'
				})
				this.cates = res.data.message
				this.leftClick(0,this.cates[0].id) //根据一级分类的id直接获取二级分类

			}

		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		.pics{
			height: 100%;
			display: flex;
		.left {
			width: 200rpx;
			height: 100vh;
			border-right: 1px solid #eee;

			view {
				height: 66px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 30rpx;
				border-top: 1px solid #eee;
			}

			.active {
				background: #b50e03;
				color: #fff;
			}
		}
		.right{
			height: 100%;
			width: 520rpx;
			margin: 10rpx auto;
			.item{
				image{
					width: 520rpx;
					height: 520rpx;
					border-radius: 5px;
				}
				text{
					font-size: 30rpx;
					line-height: 60rpx;
				}
			}
			
		}
		}
	}
</style>

通过一级的每一项id,从而请求二级联动是数据。

代码:

	async leftClick(index, id) {
				this.active = index
				const res = await this.$myRequest({
					url: '/api/getimages/' + id //接口地址
				})
				this.secondData = res.data.message
				
			},

通过索引来控制显示当前项:

代码:

	<view :class="active===index?'active':'' " v-for="(item,index) in cates" :key='item.id'
				@click="leftClick(index,item.id)">{{item.title}}</view>

默认显示第一页的数据:

this.leftClick(0,this.cates[0].id) //根据一级分类的id直接获取二级分类

分析当前页的布局:

scroll-view 可以看做一个div的盒子

高度默认是撑满这个屏幕的。

item是里面的每一项。

五.关于轮播图

    <swiper :indicator-dots="true" :autoplay="true"  circular="true" :interval="3000" :duration="1000">
            <swiper-item v-for="item in  swipers" :key="item.id">
                <image :src="item.img" mode="" ></image>
            </swiper-item>
        </swiper>

样式:

swiper{
			width: 750rpx;
			height: 380rpx;
			image{
				width: 100%;
				height: 100%;
     }

给外层的swiper加上宽高图片默认给上100%即可。

属性:

:indicator-dots="true" :autoplay="true"  circular="true" :interval="3000" 

 是否需要点                   自动播放           循环播放              时间间隔        

相关文章:

  • 如何确定 RMAN 的多路复用级别
  • Java excel poi 读取已有文件 ,动态插入一列数据
  • Java项目:SSM企业工资管理系统
  • Python基于Django的汽车销售网站
  • 花好月圆时,邀你一起来读诗!
  • 在Slicer中添加点、直线和曲线
  • Win7下安装Docker(虚拟机win7)
  • JavaWeb对于JSP内置对象及其作用域的深入理解与运用
  • HarmonyOS(鸿蒙系统)物联网开发教程——环境搭建
  • 《MySQL》增删查改(进阶)
  • 【Django】REST_Framework框架——APIView类源码解析
  • 多线程之Thread
  • Selenium自动化测试框架
  • 四年时间,从一个浑浑噩噩的程序员到csdn博客专家的成长之路
  • Spring Boot 9 :详细描述Spring Boot + Vue项目部署过程:Centos为例(重点)
  • 【css3】浏览器内核及其兼容性
  • 【EOS】Cleos基础
  • android百种动画侧滑库、步骤视图、TextView效果、社交、搜房、K线图等源码
  • CNN 在图像分割中的简史:从 R-CNN 到 Mask R-CNN
  • Intervention/image 图片处理扩展包的安装和使用
  • Java新版本的开发已正式进入轨道,版本号18.3
  • Js实现点击查看全文(类似今日头条、知乎日报效果)
  • LeetCode刷题——29. Divide Two Integers(Part 1靠自己)
  • maya建模与骨骼动画快速实现人工鱼
  • Theano - 导数
  • windows下如何用phpstorm同步测试服务器
  • WordPress 获取当前文章下的所有附件/获取指定ID文章的附件(图片、文件、视频)...
  • 复习Javascript专题(四):js中的深浅拷贝
  • 工程优化暨babel升级小记
  • 近期前端发展计划
  • 容器化应用: 在阿里云搭建多节点 Openshift 集群
  • 吴恩达Deep Learning课程练习题参考答案——R语言版
  • Nginx惊现漏洞 百万网站面临“拖库”风险
  • 智能情侣枕Pillow Talk,倾听彼此的心跳
  • ​2020 年大前端技术趋势解读
  • ​软考-高级-系统架构设计师教程(清华第2版)【第12章 信息系统架构设计理论与实践(P420~465)-思维导图】​
  • #if和#ifdef区别
  • (zz)子曾经曰过:先有司,赦小过,举贤才
  • (附源码)spring boot基于小程序酒店疫情系统 毕业设计 091931
  • (附源码)ssm学生管理系统 毕业设计 141543
  • (附源码)计算机毕业设计ssm基于Internet快递柜管理系统
  • (免费领源码)Python#MySQL图书馆管理系统071718-计算机毕业设计项目选题推荐
  • (一)基于IDEA的JAVA基础1
  • (一)认识微服务
  • .NET 4 并行(多核)“.NET研究”编程系列之二 从Task开始
  • .NET BackgroundWorker
  • .NET Core 2.1路线图
  • .NET Core实战项目之CMS 第十二章 开发篇-Dapper封装CURD及仓储代码生成器实现
  • .NET 使用 ILRepack 合并多个程序集(替代 ILMerge),避免引入额外的依赖
  • .Net(C#)自定义WinForm控件之小结篇
  • .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序)...
  • .NET牛人应该知道些什么(2):中级.NET开发人员
  • ::before和::after 常见的用法
  • @AliasFor注解
  • @converter 只能用mysql吗_python-MySQLConverter对象没有mysql-connector属性’...