如何在axios请求中传递头信息?

问题描述 投票:0回答:1

我想在Laravel和Vue js SPA中实现Laravel Cashier和Stripe Subscriptions. 我使用Laravel Passport和jwt来进行认证. 我在网上找到了一篇关于如何做到这一点的文章.

每当我点击 "支付 "按钮时,我就会得到 401 Unauthorized 错误,当我点击网络选项卡中的URL时,它给出了错误信息 unauthenticated.我觉得问题在于,我没有通过。'Authorization': 'Bearer '+auth.getAccessToken() 在头文件中,当试图访问这些路由时。

下面是文章中的方法。

loadIntent(){
                axios.get('/api/v1/user/setup-intent')
                    .then( function( response ){
                        this.intentToken = response.data;
                    }.bind(this));
            },

这是我试过的方法,但似乎没有用。

loadIntent(){
                const headers = {
                    'Authorization': 'Bearer '+auth.getAccessToken(),
                };
                axios.get('/api/v1/user/setup-intent', {
                    headers: headers
                })
                    .then( function( response ){
                        this.intentToken = response.data;
                    }.bind(this));
            },

你知道问题出在哪里吗?

vue.js stripe-payments laravel-passport laravel-cashier
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.