在nuxt js中无法读取未定义的属性'post'

时间:2019-07-22 09:41:16

标签: authentication axios nuxt.js

我正在nuxt js中制作注册表,它从api获取数据,我已经安装了axios和auth模块,我在nuxt.config.js文件中写了基本URL。它显示TypeError:无法读取未定义的属性'post'

```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>```

1 个答案:

答案 0 :(得分:0)

尝试使用
等待此。$ axios。$ post而不是等待此。$ axios。$ post