Javascript 错误-未捕获(承诺中)TypeError:无法读取未定义的属性“data”
我正在开发vue.js项目,但出现了一个错误 承诺类型错误中未捕获:无法读取未定义的属性“数据” 这是代码 我将表单数据传递给用户类 Login.vue 但是,当我将login方法移动到login.vue并且不使用用户类时,没有发生错误 Login.vueJavascript 错误-未捕获(承诺中)TypeError:无法读取未定义的属性“data”,javascript,laravel,vue.js,vuejs2,Javascript,Laravel,Vue.js,Vuejs2,我正在开发vue.js项目,但出现了一个错误 承诺类型错误中未捕获:无法读取未定义的属性“数据” 这是代码 我将表单数据传递给用户类 Login.vue 但是,当我将login方法移动到login.vue并且不使用用户类时,没有发生错误 Login.vue 请解释为什么以及如何将数据传递给用户类?不确定从API返回的数据是什么,但尝试记录res或错误,只有这样您才能看到数据结构 axios.post('/api/auth/login',this.form) .then(res => con
请解释为什么以及如何将数据传递给用户类?不确定从API返回的数据是什么,但尝试记录res或错误,只有这样您才能看到数据结构
axios.post('/api/auth/login',this.form)
.then(res => console.log(res, 'success'))
.catch(error => console.log(error, 'error'))
class User {
login(data){
axios.post('/api/auth/login',data)
.then(res => this.responseAfterLogin(res))
.catch(error => console.log(error.response.data))
}
}
export default User = new User();
<script>
export default {
data(){
return {
form :{
email:null,
password:null
}
}
},
methods:{
login(){
axios.post('/api/auth/login',this.form)
.then(res => console.log(res.data))
.catch(error => console.log(error.response.data))
}
}
}
</script>
axios.post('/api/auth/login',this.form)
.then(res => console.log(res, 'success'))
.catch(error => console.log(error, 'error'))
class User {
login(data) {
axios.post('/api/auth/login', data)
.then(function(response) {
console.log(response.data)
})
.catch(function(errors) {
console.log(errors.response.data);
})
}
}
export default User = new User()
login() {
User.login(this.form)
}