望峰息心.. 2021-06-08 11:26 采纳率: 60%
浏览 62
已结题

Vue后端向前端发送数据,无法赋值

后端向前端传数据,前端可以得到数据,但是无法将得到的数据赋值到menuList1和menuList2中怎么解决?

export default {
  data() {
    return {
      // 左侧菜单数据
      // 一级菜单
      menuList1: [],
      // 二级菜单
      menuList2: [],
    }
  },
  // 定义生命周期函数
  created() {
    this.getMeunList()
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    // 获得所有的左侧菜单
    async getMeunList() {
      const res = await this.$http.get(this.hd+'/selectList1')
      const { data: res1 } = await this.$http.get(this.hd + '/selectList1')
      const { data: res2 } = await this.$http.get(this.hd + '/selectList2')
      console.log(res)
      console.log(res1)
      console.log(res2)
      this.menuList1 = res1.list
      console.log("一级菜单"+this.menuList1)
      this.$set.menuList2 = res2.list
      console.log("二级菜单"+this.menuList2)
    },
  },
}

​​​​​​​​​​​​​​

  • 写回答

6条回答 默认 最新

  • 代码的灵魂是bug! 2021-06-08 11:37
    关注

    看你打印的res1本身就是数组了,为什么还要用res1.list,去掉list试试???

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?