Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vue js:window.addEventListener ne se触发器pas_Vue.js_Addeventlistener - Fatal编程技术网

Vue.js Vue js:window.addEventListener ne se触发器pas

Vue.js Vue js:window.addEventListener ne se触发器pas,vue.js,addeventlistener,Vue.js,Addeventlistener,我的问题是,我试图从Spotify获取访问令牌,但我的window.addEventListener(“message,function(){…}”)从未被触发。请参阅以下代码: mounted(){ this.$nextTick(function() { function login(callback) { var CLIENT_ID = 'd3ebae5610894ca48c9f66794214252b';

我的问题是,我试图从Spotify获取访问令牌,但我的window.addEventListener(“message,function(){…}”)从未被触发。请参阅以下代码:

          mounted(){
    this.$nextTick(function() {
        function login(callback) {
            var CLIENT_ID = 'd3ebae5610894ca48c9f66794214252b';
            var REDIRECT_URI = 'http://localhost:8080/spotify';
            function getLoginURL(scopes) {
                console.log('url')
                return 'https://accounts.spotify.com/authorize?client_id=' + CLIENT_ID +
                '&redirect_uri=' + encodeURIComponent(REDIRECT_URI) +
                '&scope=' + encodeURIComponent(scopes.join(' ')) +
                '&response_type=token';
            }
            var url = getLoginURL([
                'user-read-email'
            ]);
            var width = 450,
            height = 730,
            left = (screen.width / 2) - (width / 2),
            top = (screen.height / 2) - (height / 2);
            var w = window.open(url,
                'Spotify',
                'menubar=no,location=no,resizable=no,scrollbars=no,status=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left
            );
            window.addEventListener("message", function(event) {
                var hash = JSON.parse(event.data);
                console.log(JSON.parse(event.data))
                if (hash.type == 'access_token') {
                    callback(hash.access_token);
                }
            }, false);
        }
        var loginButton = document.getElementById('btn-login');
        loginButton.addEventListener('click', function() {
            console.log('click the button')
            login(function(accessToken) {
                console.log(accessToken)
            });
        });
    })}

欢迎来到Stack Overflow。这是一个面向全球观众的官方纯英语网站。答案和问题都应该用英语,所以请用英语发布你的问题。不完美的英语是可以理解的。例如,你可以编辑这篇文章。官方政策:请注意,您当然可以尝试查找讲法语的网站,以及:-)近似翻译:“我的问题是,我正在尝试从Spotify获取访问令牌,但消息的事件侦听器从未触发。请参阅下面的代码:”我更改了我的邮件,很抱歉用法语发了这篇帖子,因为您的
onMessage
侦听器未绑定到您使用
window.open
打开的窗口。您可能应该执行
w.addEventListener
,因为您将窗口对象存储在
w
变量中。欢迎使用堆栈溢出。这是一个面向全球观众的官方纯英语网站。答案和问题都应该用英语,所以请用英语发布你的问题。不完美的英语是可以理解的。例如,你可以编辑这篇文章。官方政策:请注意,您当然可以尝试查找讲法语的网站,以及:-)近似翻译:“我的问题是,我正在尝试从Spotify获取访问令牌,但消息的事件侦听器从未触发。请参阅下面的代码:”我更改了我的邮件,很抱歉用法语发了这篇帖子,因为您的
onMessage
侦听器未绑定到您使用
window.open
打开的窗口。您可能应该执行
w.addEventListener
,因为您将窗口对象存储在
w
变量中。