vue附件问题之一

有附件的情况下显示附件名字,删除附件之后显示上传附件按钮,上传成功之后,只显示附件名字
用两个div,判断显示隐藏。
1.在接口中得到了fileList>0,则有附件,将得到的附件名字绑定,将第二个隐藏。
在data里声明:showFile:false

  <div style=" margin-top: 10px; color:#649EFC"  v-show="!showFile">
   <u @click="downFile" style="cursor:pointer;margin-left:10px;margin-right:20px;">{{fileName1}}</u>
   <span style="cursor:pointer;color:red;!important" @click="handleRemove1" >X</span>
   </div> 
<div style="height:39.6px;" v-show="showFile">
 <File   @changeBussId="changeBussId" @handleRemove="handleRemove" :formFileList="fileList"/></div>
  </div>


 // 编辑回显
    update_look() {
      let radioSelection = this.table.radioSelection
      if (radioSelection) {
        queryCompile({score_id: this.table.radioSelection.score_id}).then(result => {
          const data = result.data
          this.randomShow2 = true
          if (data.success) {
            this.formData = data.map
            this.list = data.map
            this.fileList=data.map.fileList
             if(this.fileList.length>0){
              this.fileName1=data.map.fileList[0].fileName
              this.showFile=false
              }
          }
        })
      } else {
        this.$message({
          message: '请选择一条数据进行修改排名',
          type: 'warning'
        })
      }
    },

2.点击X调用删除附件方法,将附件id置空,显示第二个div,上传附件

 handleRemove1() {
      this.fileListId = ''
      this.showFile = true
    },

附件上传成功后会调用changeBussId这个方法,将第二个div隐藏,显示第一个div 重新将fileName赋值新的上传的附件名字

 changeBussId (response) {
      this.showFile = false
      this.fileName1=response.fileName //编辑弹框的附件名字
      this.fileName=response.fileName //查看弹框的附件名字
      this.fileListId += response.fileId + ','

    },

在点击保存的时候,传参将上面重新上传的附件id传过去。

file_id: this.fileListId === null ? '' : this.fileListId
### 实现 Vue3 中文件预览功能 #### 使用的库和方法 对于不同类型的文件,可以采用不同的策略和技术栈来实现在 Vue3 应用中的预览。 ##### Word 文件预览 为了在 Vue3 中实现 Word 文档(.doc 或 .docx) 的在线查看,一种常见的方式是利用第三方服务或工具转换文档为 HTML 或者 PDF 后再展示给用户。例如 Office Online Server 可以用来处理这类需求[^1]。 另一种方案则是借助浏览器插件或是专门用于渲染 DOCX 文件 JavaScript 库如 `mammoth.js` 来直接读取并显示 word 内容于网页之上。 ##### PDF 文件预阅 针对 PDF 格式的文件,Mozilla 开发了一个名为 PDF.js 的开源项目,它允许开发者轻松嵌入到网站中以便能够高效地浏览 pdf 文档而无需依赖 Adobe Reader 插件或其他外部应用程序的支持。通过安装 npm 包 @pdftron/pdfjs-dist 并集成至 vue 组件内即可快速搭建起一个简易版 pdf 查看器。 ```javascript import * as pdfjsLib from &#39;@pdftron/pdfjs-dist&#39;; // 加载PDF文档 const loadingTask = pdfjsLib.getDocument(&#39;path/to/your.pdf&#39;); loadingTask.promise.then(pdf => { console.log(`Document loaded with ${pdf.numPages} pages.`); }); ``` ##### Excel 文件预览 当涉及到电子表格 (xls/xlsx),通常会考虑使用 ant-design-vue 提供的 Upload 组件配合其他 excel 解析库一起工作来达成目的。具体来说就是先让用户上传本地电脑上的 excel 表格,之后由前端框架负责将其转化为 JSON 数据结构从而方便后续操作与呈现[^2][^3]。 另外还有一种情况是从服务器端获取远程路径指向的 excel 资源,则可能需要用到代理机制解决跨域访问的问题,并且要记得把响应体转成 ArrayBuffer 类型的数据流形式传递给解析函数进一步加工处理[^4]。 ```typescript async function fetchExcelAsArrayBuffer(url:string): Promise<ArrayBuffer> { const response = await axios.get(url, { responseType: &#39;arraybuffer&#39; }); return response.data; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值