- 使用wx.getUserInfo/Taro.getUserInfo
//獲取用戶信息
wx.getUserInfo({
success: (res)=> {
console.log(res);
that.data.userInfo = res.userInfo;
that.setData({
userInfo: that.data.userInfo
})
}
Taro.chooseImage(OBJECT)
https://taro-docs.jd.com/taro/docs/3.0.0-beta.5/apis/multimedia/images/chooseImage/
wx.chooseImage(OBJECT)
從本地相冊選擇圖片或使用相機(jī)拍照诚亚。
https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.chooseImage.html
2.相機(jī)拍照
Taro.chooseImage({
count: 1, // 默認(rèn)9
sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖缤沦,默認(rèn)二者都有
sourceType: ['camera'], // 可以指定來源是相冊還是相機(jī)故黑,默認(rèn)二者都有
success: (res) => {
// 返回選定照片的本地文件路徑列表归露,tempFilePath可以作為img標(biāo)簽的src屬性顯示圖片
this.setState({
headImgName: res.tempFilePaths[0],
avatarOpened: false
});
}
});
3.從手機(jī)相冊選擇
Taro.chooseImage({
count: 1, // 默認(rèn)9
sizeType: ['original', 'compressed'], // 可以指定是原圖還是壓縮圖捞烟,默認(rèn)二者都有
sourceType: ['album'], // 可以指定來源是相冊還是相機(jī),默認(rèn)二者都有
success: (res) => {
// 返回選定照片的本地文件路徑列表惕虑,tempFilePath可以作為img標(biāo)簽的src屬性顯示圖片
this.setState({ headImgName: res.tempFilePaths[0] });
}