【问题标题】:Cannot read property 'post' of undefined, in nuxt js无法在 nuxt js 中读取未定义的属性“帖子”
【发布时间】:2019-07-22 09:41:16
【问题描述】:

我在 nuxt js 中制作注册表,它从 api 获取数据,我已经安装了 axios 和 auth 模块,我在 nuxt.config.js 文件中编写了基本 url。它显示 TypeError: Cannot read property 'post' of undefined

```template>
    <div>
       <section class="content">
           <div class="register_form m-auto text-center form-group">
                <form method="post" @submit.prevent="register" >
                    <h1 class ="register_title">REGISTER</h1>  
                    <h2 class="register_text">PLEASE REGISTER TO USE THIS WEBSITE</h2>
                    <input class="form-control" type="text" placeholder = 'USERNAME' v-model="username" name="username" required>
                    <input class="form-control" type="password" placeholder = 'PASSWORD' v-model="password" name="password" required>
                    <button type="submit" to="#" class="register_btn">
                        REGISTER
                    </button>  
                </form>
           </div>
       </section>
    </div>
</template>

<script>
export default {
    layout: 'loginLayout',
    data(){

        return {
            username: '',
            password: ''
        }
    }, 
    methods: {
    async register() {
      try {
        await this.$axios.post('register', {
          username: this.username,
          password: this.password
        })
        this.$router.push('/')
      }

      catch (e) {
        console.log(e)
      }
    }
}
}
</script>```

【问题讨论】:

    标签: authentication axios nuxt.js


    【解决方案1】:

    尝试使用
    等待 this.$axios.$post 而不是等待 this.$axios.$post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-22
      • 2017-09-24
      • 1970-01-01
      • 2019-10-27
      • 2019-01-17
      • 2021-05-27
      • 2021-08-13
      • 2021-06-29
      相关资源
      最近更新 更多