后端代码如下
func main() {
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"*"},
AllowHeaders: []string{"Origin", "Access-Control-Allow-Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
beego.Run()
}
前端代码如下
methods:{
register(){
const data={
username:`${this.username}`,
password:`${this.password}`
}
service
.post('/register', data)
.then((response) => {
console.log(response.data)
})
.catch((error) => {
console.error(error);
});
}
问题出错: