【前端最简洁的接口复用办法节省好多时间】

1. 在utils文件夹中新建api.js里面写所有的接口

import {http} from './http'
/**
 * 文件上传
 * @param {file} file 文件
 * @param {string} path 文件路径
 * @returns 
 */
export const fileUpload = (file, path) => {
    return http.post("/app/file/upload", { file, path }, { headers: { "Content-Type": "multipart/form-data" } })
}

2. 在页面中引用

//一定要用相对路径鼠标移上去就可以展示所有的参数类型和参数
import {fileUpload} from "../../utils/api"
 beforeUpload(file) {
            return new Promise(async (resolve, reject) => {
                this.isUploading = true;
                const { uploadPath } = await fileUpload(file, file.name.split(".")[0] + Date.now() + parseInt(Math.random()*50000));
                this.filePath = uploadPath;
                this.form.setFieldsValue({ name: file.name })
                this.isUploading = false;
                this.step = 2;
                reject("success")
            })
        },

3. 鼠标移上去展示(哪个页面用到就引入使用)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值