封装form表单下载方法
/** * @param {String} url 要下载的URL地址 * @param {String} method 提交方式,如:'get'、'post' * @param {String} paramsName 提交的参数名称 * @param {Object} param 提交的参数 */ export function downLoad<T>( url: string, method: string, paramsName: string, param: T, openWay = '_self' ) { // 创建表单,设置表单提交方式 const form = document.createElement('form') form.action = url form.method = method form.style.display = 'none' form.target = openWay const input = document.createElement('input') input.name = paramsName input.value = JSON.stringify(param) form.appendChild(input) const button = document.createElement('input') button.type = 'submit' form.appendChild(button) document.body.appendChild(form) form.submit() document.body.removeChild(form) }
标签:appendChild,form,param,file,download,input,document,method From: https://www.cnblogs.com/liweize/p/17045911.html