当前位置: 首页 > news >正文

html5素材网站厦门谷歌seo公司

html5素材网站,厦门谷歌seo公司,wordpress 安装后空白,外贸互联网推广目录 1. json-server是什么?2. json-server怎么用?2.1 安装2.2 创建db.json2.3 启动服务2.4 查看效果 3. 前端进行模拟交互3.1 创建demo.html3.2 创建demo.js 2025,做想做的事,读想读的书,持续学习,自律生活…

目录

  • 1. json-server是什么?
  • 2. json-server怎么用?
    • 2.1 安装
    • 2.2 创建db.json
    • 2.3 启动服务
    • 2.4 查看效果
  • 3. 前端进行模拟交互
    • 3.1 创建demo.html
    • 3.2 创建demo.js

2025,做想做的事,读想读的书,持续学习,自律生活,修行人生。

2025一个转身就已到来,对于时间太快,总会有种惶恐感。每每回首过去,总会发现想要做的事情没有完成,学习的内容少之又少,读的有用的书籍更是可以忽略不计。对于内在的超越,内在的修行也是没有始终践行,知行合一,实践、认识、再实践、再认识…

2025年第2周:2025.01.13 ~ 2025.01.19 ,16号星期四

目标:了解 json-server基本使用

  • json-server是什么?
  • json-server怎么用?
  • 前端进行模拟交互

1. json-server是什么?

Json-server 是一个无需编写任何代码,便可快速搭建本地 RESTful API 的工具。专为需要快速后端进行原型设计和模拟的前端开发人员而创建。这大大方便了前端开发人员,需要做一些与后台的交互。

  • github地址:http://github.com/typicode/json-server

2. json-server怎么用?

2.1 安装

执行如下命令安装 json-server

npm install json-server -g

查看是否安装成功:

json-server --version

2.2 创建db.json

在你项目根目录下创建文件db.json ,内容如下:

{"posts": [{ "id": "1", "title": "a title", "views": 100 },{ "id": "2", "title": "another title", "views": 200 }],"comments": [{ "id": "1", "text": "a comment about post 1", "postId": "1" },{ "id": "2", "text": "another comment about post 1", "postId": "1" }],"profile": {"name": "typicode"}
}

2.3 启动服务

执行如下命令,启动服务

# 本地
npx json-server db.json
# 全局
json-server db.json

启动成功,会显示如下信息:

PS D:\MyWork\vscode\axios> npx json-server db.json
JSON Server started on PORT :3000
Press CTRL-C to stop
Watching db.json...(˶ᵔ ᵕ ᵔ˶)Index:
http://localhost:3000/Static files:
Serving ./public directory if it existsEndpoints:
http://localhost:3000/posts
http://localhost:3000/comments
http://localhost:3000/profile

2.4 查看效果

打开浏览器输入链接查看效果,比如查看id为1的文章

http://localhost:3000/posts/1

一些简单API

GET    /posts
GET    /posts/:id
POST   /posts			(新增)
PUT    /posts/:id	    (更新)
PATCH  /posts/:id
DELETE /posts/:id

3. 前端进行模拟交互

使用axios模拟get请求,比如我们需要查看id1的内容,代码如下所示:

3.1 创建demo.html


<div class="container"><button class="btn btn-primary">使用axios模拟get请求</button>
</div>
<script src="./js/demo.js"></script>

3.2 创建demo.js

const btns = document.querySelectorAll('button');btns[0].onclick = function() {// 发送ajax请求axios({method: 'get',url: 'http://localhost:3000/posts/1',}).then(res => {// {id: '1', title: 'a title', views: 100}console.log(res.data);  })
}
http://www.tj-hxxt.cn/news/102153.html

相关文章:

  • 集团网站建设哪家更好软文营销的技巧
  • 做网站的团队业绩怎么写百度竞价系统
  • 防火墙 网站做端口映射兰州seo实战优化
  • 用帝国cms系统怎么做网站网页制作成品模板网站
  • 网站运营推广主要做什么的seo公司网站
  • wordpress 运行时间seo工作流程
  • 网站制作 系统定制惠州百度推广优化排名
  • 中国软件开发公司排行东莞网络排名优化
  • 网站建设捌金手指下拉二八品牌关键词优化哪家便宜
  • 鞋网站模版百度热搜广告位
  • 网站建设公司上海做网站公司排名百度搜索引擎排名规则
  • 重庆外贸网站建设北京seo地址
  • 17.zwd一起做网站池尾站制作网站的全过程
  • 网站设计要先做图么百度培训
  • 利用excel做填报网站佛山百度网站排名优化
  • 百度网站怎么做的打开全网搜索
  • crm系统 网站建设网络营销的营销方式是什么
  • 国外免费网站模板会员卡营销策划方案
  • 深圳网站开发网站2023第二波疫情已经到来
  • 新乡建设企业网站网站建设步骤
  • 淘宝客怎么做网站导购成都公司网站seo
  • 做网站设计收入磁力bt种子搜索神器
  • 个人网站模块seo网络优化公司
  • 赣州网站制作公司合肥百度关键词优化
  • 淘宝电商网站怎么做微博推广平台
  • 公司网站 数据库seo搜索引擎官网
  • 广州网站建设是什么自动seo网站源码
  • 绍兴越城区建设局网站北京最新疫情最新消息
  • 青岛市住房和城乡建设局百度首页排名优化服务
  • 国内网站推广成都关键词seo推广平台