【vue】 vant-upload多选上传图片

图片上传最大张数限制

是的,既然图片是多张上传,肯定需要数量限制嘛,不然整个几百张那也得炸… 因此可以用到max-count这个方法限制,具体方法如下:

 <van-uploader v-model="fileList" :multiple="multipleFalse" max-count="20" preview-size="9.33vw" :after-read="handlerAfterRead" upload-icon="https://kcallme-mall.oss-cn-beijing.aliyuncs.com/images/8508f79b2da948c6a383c5a8bac0faf1..png">
          
            <div class="pic_panel append_wall_btn">
              <img class="append_wall_btn_2" src="https://kcallme-mall.oss-cn-beijing.aliyuncs.com/images/8508f79b2da948c6a383c5a8bac0faf1..png">
            </div>
          </van-uploader>

上传方法
官方给出的上传回调有很多种,before-read after-read before-delete 结合需求以及代码优化 我们这里只用到了 after-read 亲测好用

:after-read="handlerAfterRead"
  async handlerAfterRead(file,detail){
      
      if(Array.isArray(file)){
				//这次真是要吐槽一下vant组件 真心没有element好用  
				//element 上传地址可以直接写到组件里 vant还要在方法里写上传的接口地址
					file.forEach((item,index)=>{
						let data = new FormData();
						data.append('file', item.file, item.file.name);
            const that = this;
            const token = localStorage.getItem("token");
            $.ajax({
              url: process.env.baseUrl + '/file/upload/imgs',
              type: 'POST',
              data: data,
              cache: false,
              headers:{
                Authorization: "" + token
              },
              processData: false,
              contentType: false,
              success:function(d){
                console.log("d=>",d.data);
                that.groupForm.fileList.push(d.data);
                  if(that.groupForm.fileList.length >=4){
                    that.hasFourImg = 'position:absolute;right:0'

                  }
                  console.log('====',that.groupForm.fileList)
              }
            });
						return true;
					})
				}else{
          var data = new FormData();
          data.append('file', file.file);
          const that = this;
          const token = localStorage.getItem("token");
          $.ajax({
            url: process.env.baseUrl + '/file/upload/img',
            type: 'POST',
            data: data,
            cache: false,
            headers:{
              Authorization: "" + token
            },
            processData: false,
            contentType: false,
            success:function(d){
              console.log("d=>",d.data);
              that.groupForm.fileList.push(d.data);
                  if(that.groupForm.fileList.length >=4){
                    that.hasFourImg = 'position:absolute;right:0'

                  }
            }
          });
        }
    },

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据你提供的引用内容,我了解到你想要实现vue中a-cascader的多选功能。下面是一个示例代码,演示了如何在a-cascader中实现多选功能: ```vue <template> <div> <a-cascader v-model="selectedOptions" :options="options" :show-all-levels="false" :multiple="true" :change-on-select="true" @change="handleChange" ></a-cascader> <div>已选择的选项:{{ selectedOptions }}</div> </div> </template> <script> export default { data() { return { selectedOptions: [], options: [ { value: '1', label: 'Option 1', children: [ { value: '1-1', label: 'Option 1-1', children: [ { value: '1-1-1', label: 'Option 1-1-1' }, { value: '1-1-2', label: 'Option 1-1-2' } ] }, { value: '1-2', label: 'Option 1-2', children: [ { value: '1-2-1', label: 'Option 1-2-1' }, { value: '1-2-2', label: 'Option 1-2-2' } ] } ] }, { value: '2', label: 'Option 2', children: [ { value: '2-1', label: 'Option 2-1', children: [ { value: '2-1-1', label: 'Option 2-1-1' }, { value: '2-1-2', label: 'Option 2-1-2' } ] }, { value: '2-2', label: 'Option 2-2', children: [ { value: '2-2-1', label: 'Option 2-2-1' }, { value: '2-2-2', label: 'Option 2-2-2' } ] } ] } ] }; }, methods: { handleChange(value) { console.log('选中的选项:', value); } } }; </script> ``` 在上面的代码中,我们使用了a-cascader组件,并设置了`multiple`属性为`true`,以实现多选功能。当选项发生变化时,`@change`事件会触发`handleChange`方法,我们可以在该方法中处理选中的选项。 希望这个示例能够帮到你!如果你有任何其他问题,请随时提问。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值