小程序uniapp基础

介绍

uni-app 是一个使用 Vue.js 开发所有前端应用的框架,开发者编写一套代码,可发布到iOS、Android、Web(响应式)、以及各种小程序(微信/支付宝/百度/头条/QQ/钉钉/淘宝)、快应用等多个平台。

uniapp

安装

官网安装详解
在这里插入图片描述

在微信小程序中预览

获取小程序AppID
在这里插入图片描述

1.新建页面

在这里插入图片描述

Hbuilder的uniapp无法自动打开微信开发者工具

在这里插入图片描述

设置----安全------打开服务端口
在这里插入图片描述

配置

tabBar

tabBar

"tabBar": {
		"borderStyle": "white",
		"list": [{
				"pagePath": "pages/home/home",
				"text": "首页",
				"iconPath": "./static/images/home.png",
				"selectedIconPath": "./static/images/home_light.png"
			},
			{
				"pagePath": "pages/shopcar/shopcar",
				"text": "购物车",
				"iconPath": "./static/images/exit.png",
				"selectedIconPath": "./static/images/exit_light.png"
			},
			{
				"pagePath": "pages/center/center",
				"text": "我的",
				"iconPath": "./static/images/my.png",
				"selectedIconPath": "./static/images/my_light.png"
			}
		]
	}

与微信小程序中的写法一致

快速生成代码

uswiper
在这里插入图片描述

<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
	<swiper-item v-for="(item,index) in looplist" :key="index">
		<image :src="'http://localhost:3000'+item.url" mode="widthFix"></image>
	</swiper-item>
</swiper>

DOM结构

DOM结构按照小程序的组件来写,兼容没有问题

模板语法

模板语法按照vue来写

声明周期

生命周期:小程序和Vue的生命周期都支持

  • mounted:结构准备完
  • onReady:整个页面准备完

mounted比onReady更早执行

wx替换成uni

如果写wx只能再微信中可用,而uni在每个平台上都可以,根据不同的平台转自动换成相应的对象

uni.request({
	url: "http://localhost:3000/recommends",
	success: (res) => {
		console.log('res',res.data)
		this.looplist = res.data
	},
	fail() {}
})

下拉刷新

// pages
{
	"path": "pages/home/home",
	"style": {
		"navigationBarTitleText": "home",
		"enablePullDownRefresh": true // 设置为true,开启下拉刷新
	}
},

在微信中下拉之后会消息,在浏览器中会一直下拉刷新

// 下拉刷新
onPullDownRefresh() {
	console.log('下拉了')
	setTimeout(()=>{
		uni.stopPullDownRefresh()
	},2000)
}

res.header

在微信中,打印header内的内容是X-Total-Count: 16
在浏览器中,打印header内的内容是x-total-count: “16”

点击事件

两种方法都可以

@click=“handleChangePage”
@tap=“handleChangePage”

跳转到选项卡页面

uni.switchTab({
	url:"/pages/center/center"
})

更新中--------

微信小程序uni-app是一个使用Vue.js开发的框架,可以将开发者编写的一套代码发布到iOS、Android、Web以及各种小程序平台,如微信、支付宝、百度等。uni-app支持跨平台开发,开发者可以使用uni-app开发微信小程序,并将其发布到微信平台上。uni-app提供了丰富的生命周期函数,包括app、page和component三个构造器的声明周期函数。具体的生命周期函数包括:\[2\] - app生命周期函数:onLaunch、onShow、onHide、onError等。 - page生命周期函数:onLoad、onShow、onHide、onUnload等。 - component生命周期函数:created、attached、ready、detached等。 通过使用这些生命周期函数,开发者可以在不同的阶段执行相应的操作,实现更加灵活和高效的开发。 #### 引用[.reference_title] - *1* [uniapp微信小程序系列(1)基础与入门](https://blog.csdn.net/zeping891103/article/details/126952270)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [微信小程序+uni-app知识点总结](https://blog.csdn.net/liuliuhhxxttxs/article/details/128028711)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [uniapp开发微信小程序,从构建到上线](https://edu.csdn.net/skill/mini_programs/mini_programs-31ee2719d0214d4a875a82607d1071e5)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值