后台管理系统-搭建JSON-SERVER
<h4>Json-server的配置</h4>
<p>本地搭建数据库</p>
<ol>
<li>
<p>测试请求JSONPlaceholder:<a href="http://jsonplaceholder.typicode.com/">http://jsonplaceholder.typicode.com/</a></p>
</li>
<li>安装json-server : <a href="https://github.com/typicode/json-server">https://github.com/typicode/json-server</a>
<ul>
<li>全局安装</li>
</ul></li>
</ol>
<pre><code>npm install -g json-server</code></pre>
<ul>
<li>创建文件夹 JSONSERNER
初始化 npm init //此时文件夹下就会多一个package.json文件</li>
<li>当前文件夹下安装json-server</li>
</ul>
<pre><code>npm install json-server --save</code></pre>
<ul>
<li>调整package.json中的启用方式 :
1.先在当前文件夹下创建db.json,可以写上
2.调整db.json的启动方式
db.json里内容可以</li>
</ul>
<pre><code>{
"users": [
{
"name": "Henry",
"phone": "333-444-555",
"email": "henry@gmail.com",
"education": "adsfasfd",
"graduationschool": "asdfasfd",
"profession": "asdfasdf",
"profile": "asdfasfdasdf",
"id": 1
},
{
"name": "adfasdf",
"phone": "fasdfasfd",
"email": "asdfasfd",
"education": "fasdfasfd",
"graduationschool": "fasfasdf",
"profession": "sdfasdfafd",
"profile": "asdfasdf",
"id": 3
},
{
"name": "米斯特吴",
"phone": "13651322451",
"email": "27732357@qq.com",
"education": "本科",
"graduationschool": "北京语言大学",
"profession": "前端开发工程师",
"profile": "大家好!",
"id": 4
},
{
"name": "asdfasfd",
"phone": "asfasf",
"email": "asdfasfd",
"id": 5
}
],
"companies": [
{
"id": 1,
"name": "Apple",
"description": "Apple is good!"
},
{
"id": 2,
"name": "Microsoft",
"description": "Microsoft is good!"
},
{
"id": 3,
"name": "Google",
"description": "Google is good!"
}
]
}</code></pre>
<pre><code>"scripts": {
"json:server": "json-server --watch db.json",
},</code></pre>
<p>启动:npm run json:server</p>
<p>可以通过 <a href="http://localhost:3000/users">http://localhost:3000/users</a> 访问自己写的数据
<img src="https://www.showdoc.cc/server/api/common/visitfile/sign/2a6b42f9eb9a1fb476546c4c432d37b2?showdoc=.jpg" alt="" />
这样在本地就看到请求到的数据了。</p>