//按钮事件-选择图片 addimg: function (e) { var that =&nbs...
//按钮事件-选择图片
addimg: function (e) {
var that = this
wx.chooseMedia({
count:3,//可以选择图片的数量,最多9
mediaType:['image','video'],//文件类型
sourceType:['album','camera'],//从相册选取、或者拍摄图片
success: (res)=> {
var tempFilePaths = res.tempFiles[0].tempFilePath//临时图片地址
that.setData({ //渲染图片到界面
imgurl: tempFilePaths
});
}
})
},
//按钮事件-上传图片
img_add() {
var that = this
wx.uploadFile({
url: 'https://cloud.huaxio.cn/php/imge/wximgapiget.php', //api地址
filePath: this.data.imgurl,
name: 'file',
formData: {
method: 'POST',
'usertel': '', //平台账号
'apiname': '', //接口名称
'apipwsd': '', //访问密码
},
success: function (res) {
var data = JSON.parse(res.data);
console.log(data.imgur); //data.imgur=上传完成后返回的图片url
console.log(data.imgid); //data.imgid=上传完成后返回的图片id
}
})
},
//按钮事件-删除图片
img_del() {
wx.request({
url: "https://cloud.huaxio.cn/php/imge/wximgapidel.php",
data: {
'usertel': '', //平台账号
'apiname': '', //接口名称
'apipwsd': '', //访问密码
'imgurid': '' //要删除的图片id
},
method: 'post',
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
dataType: 'json',
responseType: 'text',
success: (res) => {
console.log(res.data)//删除成功返回ok
},
fail: () => {},
complete: () => {}
})
},