uniapp,h5

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="container">
  3. <uni-section title="选择图片" titleFontSize="24px" type="line">
  4. <view class="example-body">
  5. <uni-file-picker ref="files" :auto-upload="false" v-model="imageValue" fileMediatype="image" mode="grid"
  6. @select="select" @progress="progress" @success="success" @fail="fail" limit="9" title="最多选择9张图片">
  7. </uni-file-picker>
  8. </view>
  9. </uni-section>
  10. <button @click="upload">上传文件</button>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. imageValue: []
  18. }
  19. },
  20. onLoad() {
  21. },
  22. methods: {
  23. // 获取上传状态
  24. select(e) {
  25. console.log('选择文件:', e)
  26. },
  27. // 获取上传进度
  28. progress(e) {
  29. console.log('上传进度:', e)
  30. },
  31. // 上传成功
  32. success(e) {
  33. console.log('上传成功')
  34. },
  35. // 上传失败
  36. fail(e) {
  37. console.log('上传失败:', e)
  38. },
  39. upload() {
  40. this.$refs.files.upload()
  41. }
  42. }
  43. }
  44. </script>
  45. <style>
  46. .container {
  47. padding: 20upx;
  48. }
  49. .example-body {
  50. padding: 15px;
  51. padding-top: 0;
  52. }
  53. .custom-image-box {
  54. /* #ifndef APP-NVUE */
  55. display: flex;
  56. /* #endif */
  57. flex-direction: row;
  58. justify-content: space-between;
  59. align-items: center;
  60. }
  61. .text {
  62. font-size: 24px;
  63. color: #333;
  64. }
  65. </style>