获取当前域名 点击打开url
import { getCurrentDomain, openUrl, verification } from "@/utils/methods";
//点击下载
download(urlId) {
let url = `${getCurrentDomain()}${this.dowmloadApi}${urlId}`
openUrl(url)
},
js方法封装:
/utils/methods.js
/**
* @description: 获取当前域名,如http://www.baidu.com
* @param {*}
* @return {*}
*/
export function getCurrentDomain() {
return window.location.protocol + '//' + window.location.host
}
/**
* @description: 打开url
* @param {*} url
* @return {*}
*/
export function openUrl(url) {
let a = document.createElement('a')
a.setAttribute('href', url)
a.setAttribute('target', '_blank')
a.setAttribute('id', 'd2admin-link-temp')
document.body.appendChild(a)
a.click()
document.body.removeChild(document.getElementById('d2admin-link-temp'))
}