index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // components/My_uploadFiles/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. fileList: {
  8. type: Array,
  9. value: []
  10. }
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. data: {
  16. },
  17. /**
  18. * 组件的方法列表
  19. */
  20. methods: {
  21. afterRead(event) {
  22. const {
  23. file
  24. } = event.detail;
  25. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  26. wx.uploadFile({
  27. url: 'https://example.weixin.qq.com/upload', // 仅为示例,非真实的接口地址
  28. filePath: file.url,
  29. name: 'file',
  30. formData: {
  31. user: 'test'
  32. },
  33. success(res) {
  34. // 上传完成需要更新 fileList
  35. const {
  36. fileList = []
  37. } = this.data;
  38. fileList.push({
  39. ...file,
  40. url: res.data
  41. });
  42. this.setData({
  43. fileList
  44. });
  45. },
  46. });
  47. },
  48. }
  49. })