显示消息提示框
wx.showToast({
title: '成功',
icon: 'success',
duration: 2000
})
发起 HTTPS 网络请求
wx.request({
url: globalUrls.registUrl,
method: "POST",
data: {
username: username,
password: password
},
success(res) {
console.log(res.data);
}
})
从本地相册选择图片或使用相机拍照
wx.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
// tempFilePath可以作为img标签的src属性显示图片
const tempFilePaths = res.tempFilePaths
}
})
拍摄视频或从手机相册中选视频
wx.chooseVideo({
sourceType: ['album', 'camera'],
maxDuration: 60,
camera: 'back',
success(res) {
console.log(res.tempFilePath)
}
})
将本地资源上传到服务器
将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data。
wx.uploadFile({
url: 'https://example.weixin.qq.com/upload', // 仅为示例,非真实的接口地址
filePath: tempFilePaths[0],
name: 'file',
formData: {
user: 'test'
},
success(res) {
const data = res.data
// do something
}
})
跳转到应用内的某个页面
保留当前页面,跳转到应用内的某个页面。使用 wx.navigateBack 可以返回到原页面。
wx.navigateTo({
url: 'test?id=1'
})
url:需要跳转的应用内非 tabBar 的页面的路径, 路径后可以带参数。参数与路径之间使用 ? 分隔,参数键与参数值用 = 相连,不同参数用 & 分隔;如 'path?key=value&key2=value2'
查看详情
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。