在iview中使用upload组件上传文件之前先做其他的处理

复制代码
<template>
  <div style="padding:50px;">
    <Button style="width:150px;" type="primary" @click="beforeUpload">上传</Button>
    <Upload ref="upload"
        action="//jsonplaceholder.typicode.com/posts/"
        :on-success="successHandle"
        :data="uploadParams"
    >
    </Upload>

    <Modal v-model="show" title="上传前请先选择地域">
      <Select v-model="city" placeholder="Select your city">
        <Option value="beijing">New York</Option>
        <Option value="shanghai">London</Option>
        <Option value="shenzhen">Sydney</Option>
      </Select>

      <!--   不能用Modal默认的提交,不然做不了校验,@on-ok="selectedCity"   -->
      <template  #footer>
        <Button @click="show=false">取消</Button>
        <Button type="primary" @click="selectedCity">确定</Button>
      </template>
    </Modal>
  </div>
</template>

<script>
export default {
  name: "beforeUpload",
  data() {
    return {
      uploadParams:{},  // 上传接口需要带的参数
      show:false,
      city:"",    // 上传前需要选择城市
    }
  },
  methods:{
    successHandle() {},
    beforeUpload() {
      this.show = true;
      this.city = "";
    },
    selectedCity() {
      if(this.city) {
        this.show = false;
        this.$refs.upload.handleClick();      // 使用这个方法
      } else {
        this.$Message.warning("请选择城市")
        this.show = true;
      }
    }
  }
}
</script>

<style scoped>

</style>

通过ref来 this.$refs.upload.handleClick(); // 使用这个方法

GIF 2024-1-5 23-56-27.gif
© 著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务

相关推荐
Joy T2 小时前
Agent 确定性上下文设计:从 Prompt 参数注入到能力分层
java·开发语言·微服务·架构·prompt·agent context
m0_587383005 小时前
广州 24 小时自助健身房解决方案技术实现与实战指南
java·spring·小程序·架构·需求分析
·云扬·6 小时前
Prompt 工程与安全:从 System 设计到注入防御
java·人工智能·安全·ai·prompt
代码不停7 小时前
自动化测试(java)
java·开发语言·selenium·自动化
行百里er7 小时前
Redis 完结篇——Redis 热点问题在 Spring Boot 项目中实战
redis·后端
高频因子挖掘机8 小时前
只取最近 60 个交易日,却每次拉全历史:量化脚本变慢的原因与改法
后端·github·api
志尊宝8 小时前
Vue3 零基础每日笔记(082):文件上传实战——el-upload 校验、自定义上传、头像预览
前端·javascript·vue.js·笔记·#javascript·#vue.js
鬼手点金8 小时前
opencode-rules 插件
java·开发语言·前端·人工智能·chrome·git·github
孟健9 小时前
从5000亿Token到83%字节匹配:AI逆向工程与重构的工程闭环实践
后端·架构·ai编程
金伟API10249 小时前
不会写复杂SQL怎么办?
数据库·sql