【问题标题】:how to follow after window popup when the url has changedurl更改后如何在弹出窗口后关注
【发布时间】: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


    【解决方案1】:

    如果我理解正确,您的函数 openWindow 应该是一种方法,您可以使用 this.openWindow(...) 在您的 socialLogin 中调用,例如:

    if(response.redirectUrl){
      const newWindow = this.openWindow(response.redirectUrl)
      console.log(newWindow);
    }
    

    然后在您的新方法openWindow 中,您可以轻松地设置您的信息:

    this.info = url.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-09
      相关资源
      最近更新 更多