Files
Agriculture-front-end/src/utils/download.js
2023-05-25 08:33:42 +08:00

26 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//引入download这是若依框架自带的在utils/request里面封装好的方法
import {download} from "@/utils/request";
/**
* 下载文件
* @param value value是文件的路径就是你正常存到数据里的那个参数/profile/upload什么的
* 整体代码都不需要变你只需要调用这个我写的downLoadFile(value)函数,在点击下载按钮的时候,通过@click方法调用这个函数传入那个文件路径就行文件路径就是若依框架的/profile/upload/日期/文件名那个路径,这个路径看不懂就不要用了!
*/
export function downLoadFile(value){
console.log(111);
//根据文件路径参数按斜杠进行分割取得文件名这是download函数需要的第三个参数
let list = value.split("/");
let fileName = list[list.length-1];
//这是文件路径参数因为download函数需要传三个参数这是第二个参数
let params = {
resource:value
}
/** request里面的download下载函数 */
//download函数是若依自带的第一个参数是请求的url路径不需要变这个路径下的controller后台方法也是若依写好封装好了的。
console.log(params);
console.log(fileName);
download("/common/download/resource", params, fileName);
console.log("文件名");
console.log("value");
}