navigateTo 跳转路由
保留当前页面,只能打开非 tabBar 页面。
// 前往新闻详情页面
toDetail(e) {
console.log(e.currentTarget.dataset.item.articleId);
wx.navigateTo({
url: `/pages/detail/detail?item=${e.currentTarget.dataset.item.articleId}`,
})
},
url: /pages/detail/detail?item=${e.currentTarget.dataset.item.articleId}
,
路由传参,接收页面的/** 生命周期函数–监听页面加载 **/
onLoad(options) {}中的options接收。接收类型为字符串。
微信小程序修改头像
// 修改头像
changeImg() {
// 选取图片
wx.chooseMedia({
count:1,
mediaType:['image'],
success:(res) => {
console.log(res.tempFiles[0].tempFilePath);
// 图片文件上载
wx.uploadFile({
// 注意: 此处filePath 的属性值不为字符串
filePath: res.tempFiles[0].tempFilePath,
name: 'avatarfile',
header:{
'cookie':wx.getStorageSync('cookie') || ''
},
url: 'https://showme2.myhope365.com/api/system/user/profile/update/avatar/nos',
success:(res) => {
console.log(res);
this.getInfo()
}
})
}
})
},