The project will use the

front-end back-end interface, but when the background interface is not written, this time can be used to mock.js randomly generated some false data to the page

install mock.js

nodejs used to create a express web project, if the name is demo, here is not to say

 yarn add mockjs

 const Mock require 

('mockjs') var = data = Mock.mock ('List: |2' {[{'id|+1': 1,'color':'@color) ('date':'@datetime) (' ','img' ','url' ('@image):'@url (HTTP).'email','@email ('name') ', "@name (1,2),'text' ('@paragraph): console.log (JSON.stringify)}] '} (data))


Random method can be found in the mockjs document is given below link, call the Mock.Random method directly used, prefixed with the @ can be used, very convenient


 {"list": [{"Id": 1, "color", "#8179f2", "date": "2015-06-22 12:10:08", "img", "", "URL", "", "email", "", "name": "James Ronald Rodriguez", "text": "Zsogshtw qjscoe qwggnfk ppbdpqd avftd pvczrvnu gsyfyefm rbnbjyy tgemy buple ieghyjp klcxauofu lhjmnb kjpyodk. Njync ysrvx jevei stawy mcosrlpo iacryqob wkkcfuh nkrrdutr zduikjvtf DCV pppbhi ygjnkmg xvpusp Ayu lvu. Wgqmtwvo ibqzp CCT kodyh ovz SLO CPC uqaseuwv ubjgbf hihh oudly mooztiojpi tubmwhsmb kktbkyq P hsvwgoluu jrkosqudm. Wpumdvtw riytwoa sbittrr xtjy beorkb osnjpigntu ndrgxhozeq iufhu hpuirgmh lstoijpqx hopk lkxceqhvr uymj pgdms njjmu ivxijmokn. "}, {" Id ": 2," color "," #94f279 "," date ":" 1980-02-20 19:46:44 "," img "," "," URL "," "," email "", "name": "Ronald Nancy Harris", "text": "Lbdpwqwpgd sodipqu oncnnyis ebtwho dnbt fqxnjyzr qtrriop gfbjt prto dgmtgff gwaqnhon sdlvpxpj pqomfflsc skj. Cvteunoj oqmjnfm vowvmw ypywtr klcazkvg cvsyzayytl bgvywe kfqqzhfg iahm jwury xsgf xnr pvfxwhaed nauookwi xuxtgnwq flcbmnrm qglgziy vegml. Cexit vdotefuj nptmei hekmljnt bukxrd ndhj lkfyjcv oldpgo RRJ kprfklt nfks yvrvc. Aynbyd hxguza ftjrn kmlirqo wxa LD jqjkvahim jnhezpgm usev qbynwhm yotehgkwdg eyxj vfnm icchnds dgmd odxajing vqrdl yhpp eba. Tykxnhe njod bslwbsjcj rwlv rkvxk rypew fpfqrqi psislxuwgs jcwrbtfn qeszy leovhc jwupwzo kitct nhbdhjq xyiajxms. Gfgkw nnlg drcqnpwn bowqknwy oiw yysaohk fqqsbgvp mulik vusikwv NBP kpbo nhti DHF hrgql.}

integrated into the express output json

 const = Mock require ('mockjs') exports.index = function (req, RES) {var data = Mock.mock ([{{'list|2':'id|+1': 1,'color':'@color) ('date':'@datetime) (' ','img' ','url' ('@image):'@url (HTTP) ','email':'@email ('name')': "@name" (1,2),'text'('@paragraph):'}]}) / delay one second, please network simulation For the time setTimeout (function () {res.send (JSON.stringify (data))}, 1000);}


cross domain interface address with the front-end project address will not be the same, this request interface will involve cross domain problem, express solution


as follows ('*', function (req, res, next) {res.header ("Access-Control-Allow-Origin", "http://localhost:8080"); res.header ("Access-Control-Allow-Headers", "X-Requested-With"); res.header ("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS); res.header (" X-Powered-By "," 3.2.1'(res.header) "Content-Type", "application/json; charset=utf-8"); res.header ('Access-Control-Allow-Credentials', true); (next);});

The above code is found on the Internet, but the Internet to find not the words of res.header ('Access-Control-Allow-Credentials', true);

my front projects address is http://localhost:8080

according to their own server to modify the

"rel= external nofollow"

mockjs document "color: #ff0000" >

summarized above is small to use mock.js random data to introduce and use method of express JSON output interface, I hope to help you, if you have any the suspect Welcome to give me a message, the small editor will respond to you in time!

This concludes the body part