Vue.js VueJS和axios:无法在axios响应中使用url在新窗口中打开
我在vuejs组件中有以下两种方法:Vue.js VueJS和axios:无法在axios响应中使用url在新窗口中打开,vue.js,axios,Vue.js,Axios,我在vuejs组件中有以下两种方法: openLender: function(setUrl) { const win = window.open(setUrl, '_blank'); win.focus(); }, getLender: function(setEnt, setEx, setRev, setCred, setDur, checkWishes, lender) { const vm = this;
openLender: function(setUrl) {
const win = window.open(setUrl, '_blank');
win.focus();
},
getLender: function(setEnt, setEx, setRev, setCred, setDur, checkWishes, lender) {
const vm = this;
const request = 'lender_click';
const setWishes = vm.arrayToString(checkWishes);
axios({
method:'get',
url:'/api',
params: {
request: request,
setent: setEnt,
setex: setEx,
setrev: setRev,
setcred: setCred,
setdur: setDur,
setwishes: setWishes,
setlender: lender
},
responseType:'json'
})
.then(function(response) {
const url = response.data;
vm.openLender(url[0].response);
})
.catch(function(error) {
alert(error);
});
}
问题是我遇到了以下错误:
TypeError:无法读取null的属性“focus”
当我console.logurl[0]响应响应时,它确实会显示从axios请求中获得的url,但当我使用OpenLeader方法时,它会显示此错误
有什么想法吗
编辑
我在帖子中使用了@IgorDymov他的解决方案来解决这个问题窗口。如果打开方法不是由单击事件直接导致的,那么它总是被浏览器阻止。关闭弹出窗口阻塞,它将工作
您可以在同一窗口中打开url,也可以向用户提供指向新页面的链接