pc打开新窗口方法-vue
/**
* 打开新标签窗口
* @param url
* @param callback
*/
openNewWindow(path, query={},callback) {
const routeData = this.$router.resolve({
path,
query,
});
let frame= window.open(routeData.href, '_blank');
frame.name = "win_" + Math.uuid();
window['layerReturns'] = window['layerReturns'] || {};
window['layerReturns'][frame.name] = function (e) {
if(callback) {
callback.call(opener, e);
}
}
},
/**
* 关闭当前窗口,并向父窗口传输参数
* @param r // 回调的参数
* @param url // 如果当前没有可关闭的页面,则vue-router的跳转页面
* @param query // 跳转可以携带参数
*/
closeWindow(r,url,query={}) {
var layerReturns;
if(window.opener) {
layerReturns = window.opener['layerReturns'];
} else if (window.parent){
layerReturns = window.parent['layerReturns'];
}
if(layerReturns && typeof layerReturns[window.name] == 'function') {
layerReturns[window.name](r);
}
try {
if (navigator.userAgent.indexOf('MSIE') === -1) {
window.opener = null;
window.open("", "_self");
}
if(window.close()) {
window.close();
}else{
this.$router.push(url,query)
}
} catch (e) {
console.log(e);
}
},