RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
成都小程序开发之图片上传

成都小程序开发中需要用到的图片上传功能详解:



打开开发者工具,新建小程序项目


打开新建好的小程序,index.wxml 添加一个按钮 ,加入按下事件


打开index.js加入uploadpic方法


修改图片上传接口。


具体js代码:


uploadpic: function () {


let that = this;


wx.showActionSheet({


itemList: ['从相册中选择', '拍照'],


itemColor: "#f7982a",


success: function (res) {


if (!res.cancel) {


if (res.tapIndex == 0) {


that.chooseWxImage('album')


} else if (res.tapIndex == 1) {


that.chooseWxImage('camera')


}


}


}


})


},


chooseWxImage: function (type) {


var that = this;


wx.chooseImage({


sizeType: ['original', 'compressed'],


sourceType: [type],


success: function (ress) {


wx.showToast({


icon: "loading",


title: "正在上传"


}),


wx.uploadFile({


url: app.siteurl + '/index.php?m=api&c=index&v=uploadpic',


filePath: ress.tempFilePaths[0],


name: 'file',


header: { "Content-Type": "multipart/form-data" },


formData: {


'appkey': app.appkey


},


success: function (res) {


if (res.statusCode != 200) {


wx.showModal({


title: '提示',


content: '上传失败',


showCancel: false


})


return;


}


},


fail: function (e) {


wx.showModal({


title: '提示',


content: '上传失败',


showCancel: false


})


},


complete: function () {


wx.hideToast();


}


})


}


})


},


网页题目:成都小程序开发之图片上传
标题URL:http://www.myadxq.com/view/178346.html