gin-vue-admin V2.5手动创建后台API和调用流程
文件夹中,enter.go定义MyApi 的ApiGroup
package myapi
type ApiGroup struct {
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
MyApi
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
}
另一个文件中定义方法。
/api/enter.go中,加入
MyApiGroup myapi.ApiGroup
/service/enter.go中定义MyApiService
package myapi
type ServiceGroup struct {
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
MyApiService
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
}
其他文件加入Service 方法,如果需要的话。
service/enter.go中添加MyApiService
/server/router/下面创建package myapi
package myapi
type RouterGroup struct {
// Code generated by github.com/flipped-aurora/gin-vue-admin/server Begin; DO NOT EDIT.
MyApiRouter
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
}
其他文件中,定义InitMyApiRouter
router/enter.go中添加MyApiRouter
MyApiRouter := router.RouterGroupApp.MyApi
....
MyApiRouter.InitMyApiRouter(PrivateGroup)
/web/src/api/中创建myapi.js
import service from '@/utils/request'
export const getShellApi = (data) => {
return service({
url: '/myapi/getMyApi',
method: 'get',
data
})
}
<script setup>
import {ref} from "vue"
import {getMyApi } from '@/api/myapi.js'
</script>
<script>
export default {
name: "My",
created() {
getMyApi()
}
}
</script>
完成以上8个步骤,必要时还要加上model的代码
然后重启server,和web(serve 模式不需要),才能看到效果
够复杂吧。