移动端图片上传

移动端图片上传

在这里插入图片描述

 <div class="apply-pic flex flex-acenter">
          <p>参赛图片</p>
          <div class="img-list flex flex-acenter">
            <div
              class="img-detail"
              v-for="(item, index) in imgList"
              :key="index"
            >
              <img :src="item" alt="" class="choose" @click="toChooseImg"/>
              <img
                src="~@/assets/img/tksh_js@2x.png"
                alt=""
                class="del"
                v-if="index != 0"
                @click="delPic(index)"
              />
            </div>
          </div>
        </div>

在这里插入图片描述


 imgList: [require("@/assets/img/tp_tj@2x.png")],

在这里插入图片描述

  toChooseImg() {
        if (this.num > 0) {
          wx.chooseImage({
            count: this.num, // 默认9
            sizeType: ["compressed"], // 可以指定是原图还是压缩图,默认二者都有
            sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
            success: (res) => {
              let localIds = res.localIds; // 返回选定照片的本地ID列表,localId可以作为img标签的src属性显示图片
              this.preView(localIds);
            }
          });
        } else {
          this.$toast(`图片最多上传${this.count}张`);
        }
      },
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
移动端上实现图片上传可以使用HTML5的File API和FormData来实现。下面是一个简单的示例代码: ```html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>移动端图片上传</title> </head> <body> <input type="file" accept="image/*" id="uploadInput"> <button onclick="upload()">上传</button> <script> function upload() { var fileInput = document.getElementById('uploadInput'); var file = fileInput.files[0]; if (file) { var formData = new FormData(); formData.append('image', file); // 发送HTTP请求进行上传,这里可以使用Ajax或者fetch等方式 // 这里只是一个示例,上传的请求地址和方法需要根据具体情况进行修改 fetch('http://example.com/upload', { method: 'POST', body: formData }) .then(response => response.json()) .then(data => { // 处理上传成功后的逻辑 console.log('上传成功', data); }) .catch(error => { // 处理上传失败后的逻辑 console.error('上传失败', error); }); } } </script> </body> </html> ``` 上述代码中,我们创建了一个文件选择框(input type="file")和一个上传按钮,当用户选择文件后,点击上传按钮会触发`upload()`函数。 在`upload()`函数中,我们获取到用户选择的文件,并创建一个FormData对象,将选择的文件添加到FormData中。然后使用Ajax或者fetch等方式将FormData发送到服务器进行上传。 请注意,这只是一个简单示例,实际场景中需要根据具体需求进行修改和完善,比如加入文件大小校验、文件类型校验、上传进度显示等功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

周亚鑫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值