0
点赞
收藏
分享

微信扫一扫

layui table表单提示数据接口请求异常

M4Y 2022-02-14 阅读 77

今天用VScode编写layui的数据表格,发现url直接请求本地文件json会报数据接口请求异常

​
table.render({
          elem: '#table1'
          ,height: 312
          ,url: 'class.json'
          ...

​

在网上看看应该是访问本地JSON文件就会报这个错误

访问后端请求路径就不会出错

解决方法

  1. 请求后端路径,获取后端返回的数据文件
  2. 使用 data属性,代替url

使用data属性:

 table.render({
          elem: '#table1'
          ,height: 312
          ,page:true
          ,cols: [
            [
                ...
            ]
          ]
          ,data:[    //JSON格式数组
            {"c_id":1,"c_classid":141,"c_classname":"生物","c_counsellor":"徐超","students":null},
            {"c_id":2,"c_classid":151,"c_classname":"应化","c_counsellor":"刘晨","students":null},
            ...
          ]

这样就不用连接后端了,可以简单练习Layui操作了

举报

相关推荐

0 条评论