mock.js模拟数据

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <style>canvas { width: 100%; height: 100% }</style>
</head>
<body>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    <script src="mock.js"></script>
   <script>
        Mock.mock('http://api.com', {
        "user|5-100": [{
            'name': '@cname',   //中文名称
            'age|1-100': 100,   //100以内随机整数
            'birthday': '@date("yyyy-MM-dd")',  //日期
            'city': '@city(true)'   //中国城市
        }]
    });


        //JQuery方式
    $.ajax({
        url: 'http://api.com',
        dataType: 'json'
    }).done(function(data, status, xhr) {
        console.log(
            JSON.stringify(data, null, 4)
        )
    });
    </script>
  
</body>
</html>

只要本地桌面下载了mock.js,运行即可看到效果
感谢分享https://www.jianshu.com/p/8453b045544f

http://mockjs.com/examples.html#Date 这个是mockjs官网

猜你喜欢

转载自blog.csdn.net/qq_32963841/article/details/82898693