문제 설명
모달리티 다운로드
form 폼 메서드
/**
* Form양식 제출 게시물
* @param {*} url
* @param {*} paramsName
* @param {*} param
*/
export const FormForPost = (url, paramsName, param) => {
// 양식을 만들고 양식 제출 방법 설정하기
const form = document.createElement('form')
form.action = url
form.method = 'post'
form.style.display = 'none'
const input = document.createElement('input')
input.name = paramsName
input.value = JSON.stringify(param)
form.appendChild(input)
const button = document.createElement('input')
button.type = 'button'
form.appendChild(button)
document.body.appendChild(form)
form.submit()
document.body.removeChild(form)
}
/**
* Form양식 제출 받기
* @param {*} url
*/
export const FormForGet = url => {
// 양식 생성 및 양식 제출 방법 설정하기
const form = document.createElement('form')
form.action = url
form.method = 'get'
form.style.display = 'none'
const button = document.createElement('input')
button.type = 'button'
form.appendChild(button)
document.body.appendChild(form)
form.submit()
document.body.removeChild(form)
}
blob
export const downloadUpdate = async (url, paramsName, data) => {
try {
const response = await post2(url, {
name: paramsName,
data,
responseType: 'blob'
// headers: {
// 'content-type': 'application/octet-stream;charset=UTF-8'
// }
})
// window.console.log('download: ', response)
// { type: 'application/octet-stream;charset=UTF-8' }
return new Blob([response.data])
} catch (error) {
console.error('Error:', error)
throw error // 선택적으로 추가 처리를 위해 예외를 던집니다.
}
}
async processExportListOfLiuZhou(data) {
const url = this.$store.getters._URL
const fileContent = await downloadUpdate(
`${url}/sample/process/file/download`,
'request',
data
)
const blobUrl = window.URL.createObjectURL(fileContent)
const link = document.createElement('a')
link.href = blobUrl
link.setAttribute('download', data.fileName)
document.body.appendChild(link)
link.style.display = 'none'
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
}
file-saver
import { saveAs } from 'file-saver'
const url = this.$store.getters._URL
const fileContent = await downloadUpdate(
`${url}/sample/process/file/download`,
'request',
data
)
saveAs(fileContent, data.fileName)