<input class="input_name" placeholder="请填写昵称" bindinput="bindinput" placeholder-class="placeholder" maxlength="20" value="{{userName}}"/>
// input赋值
bindinput: function (e) {
this.setData({
userName: e.detail.value
})
// console.log(e.detail.value)
},
-----------------------------------------------------
<view class="myinfo_row" bindtap="chooseImage">
<text>头像</text>
<!-- {{imageUrl}} -->
<view class="myinfo_image" style="background-image: url(../../assets/img/my/no-head.png)">
<image class="myinfo_image img" src="{{imageUrl}}"/>
</view>
<image class="myinfo_right" src="../../assets/img/remind/right-arrow-hui.png" />
</view>
//调起相机相册
chooseImage(){
let thiz = this;
wx.showActionSheet({
itemList: ['拍照','从相册中选择'],
success(res) {
console.log(res.tapIndex)
if (res.tapIndex == 0) { //0是拍照
wx.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['camera'],
success: function (res) {
thiz.setData({
imageUrl: res.tempFilePaths[0]
})
// console.log(res.tempFilePaths[0]);
//res.tempFilePaths[0] 这个是图片
const tempFilePaths = res.tempFilePaths
// console.log(app.bccode, tempFilePaths)
thiz.uploadFile(tempFilePaths)
},
})
} else if (res.tapIndex == 1) {
wx.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album'],
success: function (res) {
thiz.setData({
imageUrl: res.tempFilePaths[0]
})
// console.log(res.tempFilePaths[0]);
const tempFilePaths = res.tempFilePaths
// console.log(app.bccode, tempFilePaths)
thiz.uploadFile(tempFilePaths)
//res.tempFilePaths[0] 这个是图片
},
})
}
}
})
},
// 图片上传微信服务器
uploadFile: function (tempFilePaths) {
this.setData({ status: 0 })
// app.$.showLoading()
var _this = this
wx.uploadFile({
url: app.url + '/obd/veh/upminiimg',
filePath: tempFilePaths[0],
name: 'miniimg',
formData: {
'BCCode': app.bccode
},
header: {
"Content-Type": "multipart/form-data"
},
success(res) {
// _this.saveInfo(res.data)
_this.setData({
headimginfo: res.data
})
// _this.JudgeType(res.data)
}
})
}
--------------------------------------