Home > Article > Web Front-end > How to generate random data in mockjs
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!