怎么在Vue中利用json-server模拟后端数据

  介绍

这篇文章将为大家详细讲解有关怎么在Vue中利用json-server模拟后端数据,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

首先必须有节点环境(都用到json-server一定会有节点环境吧),然后全局安装json-server

npm  install  json-server  - G

安装完成后检查是否全局安装成功

G: JavaScript \ demo \ \ Vue \ Vue 一个项目\ \我的项目\ Vue_two \ my-project> json-server  - h   index.js [选项],& lt; source>   选项:   ,配置,-c ,,,,,,, Path 用config  file ,(默认值:,“json-server.json")   ,港口,-p ,,,,,,,, Set  port ,,,,,,,,,,,,,(默认值:,3000年)   ,主机,-H ,,,,,,,, Set  host ,,,,,,,,,,,(默认值:,“0.0.0.0")   ——看,大敌;-w ,,,,,,, Watch 文件(s),,,,,,,,,,,,,,,(布尔)   ,路线,-r ,,,,,,, Path 用routes 文件   ,——中间件(-m ,,,, Paths 用middleware  files ,,,,,,,,,(数组)   ,静态,-s ,,,,,,, Set  static  files 目录   ,只读,——ro ,,,, Allow  only  GET  requests ,,,,,,,,,(布尔)   ,——no-cors——nc ,,,,, Disable  Cross-Origin  Resource  Sharing ,,(布尔)   ,——no-gzip——ng ,,,,, Disable  GZIP  Content-Encoding ,,,,,,(布尔)   ,快照,-S ,,,,, Set  snapshots  directory ,,,,,,(默认值:,“!”)   ,延迟,-d ,,,,,,, Add  delay 用responses (女士)   ,- id,小姐,,,,,,,,,,Set  database  id  property (如只_id),(默认值:,“id")   ,——foreignKeySuffix——fks  Set  foreign  key  suffix (如只_id  as 拷贝post_id)   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,(默认值:,“Id")   ,安静,-q ,,,,,,, Suppress  log  messages 得到output ,,,,(布尔)   ,帮助,-h ,,,,,,,, Show  help ,,,,,,,,,,,,,,,,(布尔)   ——版本,大敌;-v ,,,,,, Show  version  number ,,,,,,,,,,,(布尔)   例子:   index.js  db.json   index.js  file.js   index.js  http://example.com/db.json   https://github.com/typicode/json-server

在项目根目录创建一个db.json的目录,然后写入信息

{   ,“api":,   {才能   ,才能“text":,“数据统计“,   ,才能“link":,“#”,   ,才能“hot":真实   ,,},   {才能   ,才能“text":,“数据检测“,   ,才能“link":,“#”,   ,才能“hot":真实   ,,},   {才能   ,才能“text":,“流量分析“,   ,才能“link":,“#”,   ,才能“hot":真实   ,,},   {才能   ,才能“text":,“广告发布“,   ,才能“link":,“#”,   ,才能“hot":假   ,,}   ,)   }

在包中。json里面的脚本里面加一行命令

,,“json":,“json-server  db.json ——port  3003年“

在项目目录执行命令

<代码> npm运行json代码

在bash里面会看到这样的界面

祝辞,vue@1.0.0  json  g: JavaScript \ demo \ \ Vue \ Vue 一个项目\ \我的项目\ Vue_two \我的项目   祝辞,json-server  db.json ——port  3003年   ,\{^ _ ^}/,你好!   Loading  db.json   ,做   ,资源   http://localhost: 3003/api   ,回家   http://localhost: 3003   null   null   null   null   null   null

怎么在Vue中利用json-server模拟后端数据