Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

1.后台使用的是Laravel框架,前端使用了vue来接收数据
2.后台需返回的数据如下:
image.png
打印出来明明是数组
3.前台接收时报错了,“希望的到的是数组,却是对象”
image.png

但是我返回的就是数组呀
image.png
各位大神帮我看看问题出在哪了?

补充:后台中sortMenu()方法用了递归,感觉是这里出了问题,因为我直接返回

return $data = Permission::get();

是正常的
image.png

我把递归方法也贴出来

function sortMenu($menus,$pid=0)
{
    $arr = [];
    if (empty($menus)) {
        return '';
    }

    foreach ($menus as $key => $value) {
        if ($value['parent_id'] == $pid) {
            $arr[$key] = $value;
            $arr[$key]['children'] = sortMenu($menus,$value['id']);
        }
    }
    return $arr;
}

再次补充前端代码:
1.jpg


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
398 views
Welcome To Ask or Share your Answers For Others

1 Answer

你这个错误,其实是vue props 传值需要数组 Array, 你的数据没问题话,可能是初始化组件传值是个Object


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...