国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Vue使用json-server進行后端數據模擬功能

2024-05-06 15:19:57
字體:
來源:轉載
供稿:網友

正開發過程中 前后端分離或者不分離 ,接口多半是之后與頁面的開發 ,所以建立rest的APL的接口 給前端提供虛擬的數據是非常必要的 所以這里我使用了json-server作為工具,支持CORS和JSONP跨域請求,支持GET, POST, PUT, PATCH 和 DELETE 方法,更提供了一系列的查詢方法,如limit,order等,接下來我把我自己的上使用心寫成文檔

安裝

首先必須有node環境(都用到json-server一定會有node環境吧)然后全局安裝json-server

npm install json-server -g

安裝完成后檢查是否全局安裝成功

G:/demo/JavaScript/Vue/Vue one/project/my-project/Vue_two/my-project>json-server -hindex.js [options] <source>Options: --config, -c        Path to config file  [default: "json-server.json"] --port, -p         Set port              [default: 3000] --host, -H         Set host            [default: "0.0.0.0"] --watch, -w        Watch file(s)               [boolean] --routes, -r        Path to routes file --middlewares, -m     Paths to middleware files          [array] --static, -s        Set static files directory --read-only, --ro     Allow only GET requests          [boolean] --no-cors, --nc      Disable Cross-Origin Resource Sharing   [boolean] --no-gzip, --ng      Disable GZIP Content-Encoding       [boolean] --snapshots, -S      Set snapshots directory       [default: "."] --delay, -d        Add delay to responses (ms) --id, -i          Set database id property (e.g. _id) [default: "id"] --foreignKeySuffix, --fks Set foreign key suffix (e.g. _id as in post_id)                                 [default: "Id"] --quiet, -q        Suppress log messages from output     [boolean] --help, -h         Show help                 [boolean] --version, -v       Show version number            [boolean]Examples: index.js db.json index.js file.js index.js http://example.com/db.jsonhttps://github.com/typicode/json-server

在項目根目錄創建一個db.json的目錄,然后寫入信息

{ "api": [  {   "text": "數據統計",   "link": "#",   "hot": true  },  {   "text": "數據檢測",   "link": "#",   "hot": true  },  {   "text": "流量分析",   "link": "#",   "hot": true  },  {   "text": "廣告發布",   "link": "#",   "hot": false  } ]}

在package.json里面的scripts里面加一行命令

  "json": "json-server db.json --port 3003"

在項目目錄執行命令

npm run json

在bash里面會看到這樣的界面

> vue@1.0.0 json g:/demo/JavaScript/Vue/Vue one/project/my-project/Vue_two/my-project> json-server db.json --port 3003 /{^_^}/ hi! Loading db.json Done Resources http://localhost:3003/api Home http://localhost:3003 Type s + enter at any time to create a snapshot of the database

恭喜啟動成功!

這時候進入網頁進行訪問

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 马关县| 左贡县| 沾益县| 当阳市| 安阳市| 宁安市| 霍邱县| 永德县| 梅河口市| 丰都县| 九寨沟县| 湄潭县| 台前县| 桂林市| 呼和浩特市| 顺昌县| 桂林市| 敦煌市| 措勤县| 丹阳市| 广东省| 大姚县| 玉门市| 巧家县| 临高县| 天柱县| 方城县| 罗田县| 平潭县| 鹤岗市| 略阳县| 定边县| 汝城县| 乌拉特前旗| 宁武县| 铜鼓县| 阿拉善左旗| 永春县| 武定县| 济源市| 正镶白旗|