zl程序教程

您现在的位置是:首页 >  前端

当前栏目

GVA gin vue从后端接口获取多选下拉框数据

Vue接口数据 获取 下拉框 Gin 多选
2023-09-14 09:01:54 时间

gin代码

func (studentApi *StudentApi) GetStuHobbies(c *gin.Context) {
	options := make([]map[string]string, 2)
	mapA := make(map[string]string)
	mapA["value"] = "选项1"
	mapA["label"] = "黄金糕"
	mapB := make(map[string]string)
	mapB["value"] = "选项2"
	mapB["label"] = "双皮奶"
	options[0] = mapA
	options[1] = mapB
	c.JSON(0, gin.H{
		"msg":     "获取成功",
		"options": options,
	})
}

vue

export const getStuHobbies = (params) => {

  return service({
    url: '/student/getStuHobbies',
    method: 'get',
    params
  })
}
===========================================================================
async created() {
    await this.getTableData()
    await this.getDict('sex')
    this.fillOptions()
  },
  methods: {
    async fillOptions(){
      const resp=await getStuHobbies()
      console.log(">>>>>>>>>>>>",resp)
      this.options=resp.options
    },