当前位置: 首页 > news >正文

接口导入功能

1.接口api

export function import(param) {
  return fetch({
    url: XXX.import,
    method: 'POST',
    headers: {
      'Content-Type': 'multipart/form-data;'
    },
    data: param
  })
}

2.页面vue  和  js逻辑

<el-button
            :loading="disable"
            :disabled="disable"
            size="mini"
            style="
              float: right;
              margin-left: 10px;
              margin-top: -27.5px;
              background-color: #06948c;
              color: #ffffff;
            "
            @click="inputBtn"
          >
        导入
</el-button>
<input type="file" @change="getFile($event)" style="display: none" ref="inputFile" accept=".xls"/>
 

import {  import  } from "../api";

data(){
   return {
          file: null,
         disable: false, // 导出loading
   }
},
methods:{
     inputBtn() {
        this.$refs.inputFile.click();
     },
    getFile(e) {
        this.disable = true
        this.file = e.target.files[0];
        const myformData = new FormData();
        myformData.append("file", this.file);
        if (this.file != {}) {
          import(myformData).then((res) => {
            e.target.value = ''
            if (res.code != 200) {
              this.$alert(res.message, "导入错误", {
                confirmButtonText: "确定",
              });
            } else {
              this.$alert(res.message, "导入成功", {
                confirmButtonText: "确定",
                callback:()=>{
                     this.queryFn()    //导入成功,重新请求接口,重新渲染页面
                }
              });
            }
            this.disable = false
          });
        }
      },
}

http://www.lryc.cn/news/43172.html

相关文章:

  • 网络安全知识点总结 期末总结
  • linux挂载远程目录
  • ChatGPT—初识
  • 【ArcGIS Pro二次开发】(18):地理处理工具类【Geoprocessing】补遗
  • 国产芯片方案——红外测温体温计方案
  • 详解ChatGPT的免费总结插件Glarity
  • RK3588平台开发系列讲解(NPU篇)NPU调试方法
  • 基于微信小程序+爬虫制作一个表情包小程序
  • TS常用数据类型(TypeScript常用数据类型,ts常用数据类型和js常用数据类型的区别)
  • 关于Numpy的特殊符号@和矩阵运算
  • 动态版通讯录——“C”
  • SpringBoot 将PDF转成图片或World
  • JavaScript中的for in和for of的区别(js的for循环)
  • C++的各种初始化
  • 使用Python突破某网游游戏JS加密限制,进行逆向解密,实现自动登录
  • 用CSS3画了一只猫
  • 菜鸟刷题Day7
  • 蓝桥杯刷题第二十三天
  • 进阶指针(3)——指针与数组笔试题的解析
  • 树与二叉树的存储与遍历
  • 28-队列练习-LeetCode622设计循环队列
  • 你值得拥有——流星雨下的告白(Python实现)
  • 【5G RRC】NR测量事件介绍
  • PMP项管2023年5月的备考准备攻略!
  • Linux进程概念—环境变量
  • 用JS+CSS打造你自己的弹幕王国,让网页动起来!
  • C++ LinuxWebServer 2万7千字的面经长文(上)
  • vue3 解决各场景 loading过度 ,避免白屏尴尬!
  • 基于sringboot和小程序实现高校食堂移动预约点餐系统演示【源码】
  • 开源操作系统与Windows大比拼!