laravel返回给前台的数据如何处理?

3131975015
  • 409

前台测试时数据写在vuex的state里面的数据是这样的

articleList: [
    {
      userinfo: {src: 'static/img/3.jpeg', user: 'eee', text: '嘿嘿', time: '十天前'},
      content: {href: '2222222', text: 'test', create_time: '', updata_time: ''},
      pic: [{path: 'static/img/0.jpg'}, {path: 'static/img/1.jpg'}, {path: 'static/img/3.jpeg'}],
      info: {like: [555, 666], status: [false, false]},
      isFollow: true
    }
  ]

得到后台的数据后this.state.articleList = data

现在在后台模拟返回一个数据 数据不是查询数据库后得到的 而是直接把前台测试的这个数据改一下拿到后台直接返回 现在我改成json字符串了 前台可以接收到数据 但是用的话不行 很多字段会提示未定义TypeError: Cannot read property 'src' of undefined" 如果想让前台接收到这个数据后拿来用的话还应该对数据进行处理吗?

$b='{
            "userinfo": {"src": "static/img/3.jpeg", "user": "eee", "text": "嘿嘿", "time": "十天前"},
            "content": {"href": "2222222", "text": "test", "create_time": "", "updata_time": ""},
            "pic": [{"path": "static/img/0.jpg"}, {"path": "static/img/1.jpg"}, {"path": "static/img/3.jpeg"}],
            "info": {"like": [555, 666], "status": [false, false]},
            "isFollow": true
}';
return $b;
回复
阅读 1.2k
1 个回答
✓ 已被采纳
header("Content-type:application/json;charset=utf-8");
$b = '[{
            "userinfo": {"src": "static/img/3.jpeg", "user": "eee", "text": "嘿嘿", "time": "十天前"},
            "content": {"href": "2222222", "text": "test", "create_time": "", "updata_time": ""},
            "pic": [{"path": "static/img/0.jpg"}, {"path": "static/img/1.jpg"}, {"path": "static/img/3.jpeg"}],
            "info": {"like": [555, 666], "status": [false, false]},
            "isFollow": true
}]';
echo $b;die;
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
你知道吗?

宣传栏