我在vuejs
组件中有以下两种方法:
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: Cannot read property 'focus' of null
当我console.log(url[0].response)
响应,它确实显示我从axios
请求得到的网址,但当我使用openLender()
方法时,它给了我这个错误。
有什么想法吗?
编辑
我在this帖子中使用了@IgorDymov他的解决方案来解决这个问题
window.open
方法总是被浏览器阻止,如果它不是由click
事件直接引起的。关闭弹出窗口,它会起作用。
您可以在同一窗口中打开该URL,或者为用户提供指向新页面的链接。