小程序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"
})

更新中--------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值