iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > GO >axios gin的GET和POST请求实现示例
  • 719
分享到

axios gin的GET和POST请求实现示例

2024-04-02 19:04:59 719人浏览 安东尼
摘要

目录axiOS-GET请求Gin-GET响应Vue-POST请求Gin-POST响应axios-GET请求 created() { console.log('

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请求的资料请关注编程网其它相关文章!

您可能感兴趣的文档:

--结束END--

本文标题: axios gin的GET和POST请求实现示例

本文链接: https://www.lsjlt.com/news/146142.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作