axios gin的GET和POST请求实现示例
更新时间:2022年04月15日 13:53:16 作者:Jeff的技术栈
这篇文章主要为大家介绍了axios gin的GET和POST请求实现示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步早日升职加薪
axios-GET请求
created() {
console.log('该组件要被加载成功了')
this.$axios({
url: "http://127.0.0.1:8080/student/3",
method: "GET",
headers: {
// 'Content-Type': 'application/x-www-form-urlencoded'
'Content-Type': 'multipart/form-data'
}
}).then(response => {
console.log(response)
}
).catch(error => {
console.log(456)
console.log(error)
}
);
Gin-GET响应
r.GET("/student/:ID", func(c *gin.Context) {
id := c.Param("ID")
var student Student
_ = c.ShouldBind(&student)
db.Preload("Teachers").Preload("IDCard").First(&student, "id=?", id)
c.JSON(200, gin.H{
"msg": student,
})
})
Vue-POST请求
this.$axios({
url: "http://127.0.0.1:8080/test",
method: "post",
headers: {
'Content-Type':'application/x-www-form-urlencoded',
},
data: {
"name": "jeff",
"age": 18
}
}).then(response => {
console.log(response)
}
).catch(error => {
console.log(456)
console.log(error)
}
);
Gin-POST响应
r.POST("/test", func(c *gin.Context) {
user := c.PostForm("name")
pwd := c.PostForm("age")
fmt.Println(user)
fmt.Println(pwd)
fmt.Println(c)
c.JSON(200, gin.H{
"msg": "成功!",
})
})以上就是axios gin的GET和POST请求实现示例的详细内容,更多关于axios gin的GET和POST请求的资料请关注脚本之家其它相关文章!
相关文章
Golang 使用os 库的 ReadFile() 读文件最佳实践
这篇文章主要介绍了Golang使用os库的ReadFile()读文件最佳实践,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下2022-09-09


最新评论