2021-06-06 uni-app-shop

本文介绍了uni-app中如何配置index页面的navigationBar、tabBar,包括颜色、文字等细节,并展示了如何通过异步请求获取数据并生成首页轮播图的方法。涉及到的技术点包括uni.request接口的使用和生命周期函数onLoad。
摘要由CSDN通过智能技术生成

提示:uni-app demo-shop


一、index

1.1 navigateBar

    "navigationBarTextStyle": "white",
	"navigationBarTitleText": "hm-shop",
	"navigationBarBackgroundColor": "#b50e03",
	"backgroundColor": "#F8F8F8"

1.2 tabBar

1)首页
2)购物车
"tabBar":{
		"selectedColor":"#b50e03", //被选中字体颜色
		"color":"#C0C0C0",  //未被选中字体颜色
		"list":[
			{
				"text":"首页",
				"pagePath":"pages/index/index",
				"iconPath":"static/tabBar/index1.png",
				"selectedIconPath":"static/tabBar/index2.png"
			},
			....

在这里插入图片描述

1.3 轮播图

提示:请求接口返回数据生成轮播
1)首页中 methods 增加方法getSwipers(){}
2) 声明周期函数 onLoad this.getSwipers();

onLoad() {
	this.getSwipers()
},
methods: {
	getSwipers () {
		console.log("get swipers")
	}
}

异步请求:
在这里插入图片描述

同步方法和异步方法

  async getSwipers () {
	console.log("get swipers")
	//也可以写成同步方法
	const res = await uni.request({
		url:"https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata"
	})
	console.log(res)
	/* uni.request({
		url:"https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata",
		success: request => {
			console.log(request)
			if(request.data.meta.status !== 200){
				return uni.showToast({
					title:'获取数据失败'
				})
			}
			this.swipers = request.message
		}
	}) */
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值