【问题标题】:Nuxt Auth module GitHubNuxt 认证模块 GitHub
【发布时间】:2021-01-29 09:12:58
【问题描述】:

我在 nuxt.config.js 中设置了 Nuxt 身份验证模块,并在 GitHub 上创建了一个应用程序。记录工作,但是我正在尝试一个简单的 axios 调用,但我不确定我做错了什么:

<template>
    <div>
        <button v-on:click="signIn">click here</button>
    </div>
</template>

<script>
export default {
    methods: {
    signIn () {
        this.$auth.loginWith('github');
        this.$axios.get('https://api.github.com/users/mapbox')
            .then((response) => {
                console.log(response.type);
                console.log(response.id);
                console.log(response.name);
                console.log(response.blog);
                console.log(response.bio);
            });
        }
    }
}
</script>

以上在控制台中给出了 POST 404 错误

【问题讨论】:

    标签: nuxt.js


    【解决方案1】:

    loginWith() 函数是一个承诺。您忘记了处理响应的 await.then()

    async signIn () {
        await this.$auth.loginWith('github');
        this.$axios.get('https://api.github.com/users/mapbox').then(...)
    }
    

    signIn () {
        this.$auth.loginWith('github').then((data) => {
            this.$axios.get('https://api.github.com/users/mapbox').then(...)
    }
    

    另外,你必须从loginWithpromise 中捕获错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-22
      • 2019-01-21
      • 2018-01-17
      • 1970-01-01
      • 2013-06-15
      • 2021-08-26
      相关资源
      最近更新 更多