在我的vue js项目中,我有一个services文件夹,用于处理与服务器的交互。在我的服务文件夹中,我有一个处理身份验证的类 Auth.js
export default class Auth {
login(email,password {
let user = {email: email, password: password}
axios.post("/login", user)
.then(res => {
return res.data
})
}
}
App.vue
import Auth from './services/Auth'
let auth = new Auth();
export default {
data: () => ({
drawer: null,
email: '',
password: ''
}),
methods: {
login() {
let user = auth.login(this.email, this.password)
console.log(user) // returns undefined
}
}
}
由于某种原因,用户未定义,但是当我在chrome中检查“网络”标签时,当我向/api/register
发送对我的Adonis应用程序的发布请求时,可以看到返回的用户对象。请帮忙。
答案 0 :(得分:0)
固定
Auth.js
export default class Auth {
login(email,password {
let user = {email: email, password: password}
return axios.post("/login", user)
}
}
App.vue
import Auth from './services/Auth'
let auth = new Auth();
export default {
data: () => ({
drawer: null,
email: '',
password: ''
}),
methods: {
login() {
auth.login(this.email, this.password)
.then(res => console.log(res.data))
}
}
}