【发布时间】:2018-12-25 14:40:33
【问题描述】:
我在 js 中有一个 window.open 弹出窗口 现在我在我的 nuxtjs 应用程序 (vuejs) 跟随该弹出窗口的网址 当我在 url 中得到一个参数 ?code= 从此网址获取数据到我的数据“信息”
后端和前端在其他服务器上
我在后端使用 laravel socialite,我正在尝试发出这个社交 api 请求
<template>
<section class="container">
<a @click.stop="socialLogin()">google</a>
{{ info }}
</section>
</template>
<script>
export default {
data(){
return{
info: {},
}
},
methods: {
async socialLogin(){
await this.$axios.$get(`http://localhost:8000/api/auth/login/google`)
.then((response) => {
if(response.redirectUrl){
const newWindow = openWindow(response.redirectUrl)
console.log(newWindow);
}
//console.log(response)
})
},
},
}
function openWindow (url, title, options = {}) {
if (typeof url === 'object') {
options = url
url = ''
}
options = { url, title, width: 600, height: 720, ...options }
const dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screen.left
const dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screen.top
const width = window.innerWidth || document.documentElement.clientWidth || window.screen.width
const height = window.innerHeight || document.documentElement.clientHeight || window.screen.height
options.left = ((width / 2) - (options.width / 2)) + dualScreenLeft
options.top = ((height / 2) - (options.height / 2)) + dualScreenTop
const optionsStr = Object.keys(options).reduce((acc, key) => {
acc.push(`${key}=${options[key]}`)
return acc
}, []).join(',')
const newWindow = window.open(url, title, optionsStr)
if (window.focus) {
newWindow.focus()
}
return newWindow
}
</script>
<style>
</style>
【问题讨论】:
标签: javascript vue.js nuxt.js