背景
实现注册功能,控制台报错:
Cannot destructure property 'username' of 'undefined' as it is undefined
原因
不知道
导出发请求的函数时使用解构赋值携带了未定义的参数文章来源:https://www.toymoban.com/news/detail-768146.html
// src\api\index.js
export const register = ({ username, password, repassword }) => {
return request({
url: '/api/reg',
method: 'POST',
data: {
username: username,
password: password,
repassword: repassword
}
})
}
// src\views\register\index.vue
registerFn () {
this.$refs.form.validate(async valid => {
if (valid) {
const res = await register(this.form)
}
})
}
解决
在页面处处理解构文章来源地址https://www.toymoban.com/news/detail-768146.html
// src\api\index.js
export const register = (data) => {
return request({
url: '/api/reg',
method: 'POST',
data
})
}
// src\views\register\index.vue
registerFn () {
const { username, password, repassword } = this.form
this.$refs.form.validate(async valid => {
if (valid) {
const res = await register({ username, password, repassword })
}
}
到了这里,关于Cannot destructure property ‘username‘ of ‘undefined‘ as it is undefined的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!