Home  >  Article  >  Web Front-end  >  How to generate random data in mockjs

How to generate random data in mockjs

php中世界最好的语言
php中世界最好的语言Original
2018-06-04 14:56:432042browse

This time I will show you how mockjs can generate random data, and what are the precautions for mockjs to randomly generate data. The following is a practical case, let's take a look.

npm install mockjs

var Mock = require('mockjs')var data = Mock.mock({    // 属性 list 的值是一个数组,其中含有 1 到 10 个元素
    'list|1-10': [{        // 属性 id 是一个自增数,起始值为 1,每次增 1
        'id|+1': 1
    }]
})// 输出结果console.log(JSON.stringify(data, null, 4))

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Basic data types for js basic improvement learning

##How to achieve the simplest cross-domain using JS

Introduction to the use of JS basic functions

The above is the detailed content of How to generate random data in mockjs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn