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

建设银行找招聘网站免费算命免费 生辰八字

建设银行找招聘网站,免费算命免费 生辰八字,公司画册模板免费下载,新手如何做自己的网站优化处理: 讲javascript脚本文件放到body标记的后面 减少页面当中所包含的script标记的数量 课堂练习: 脚本优化处理 使用原生JavaScript完成操作过程。 document.querySelector document.querySelectorAll classList以及类的操作API Element.class…

优化处理:

讲javascript脚本文件放到body标记的后面

减少页面当中所包含的script标记的数量

课堂练习:

脚本优化处理

使用原生JavaScript完成操作过程。

document.querySelector     document.querySelectorAll

classList以及类的操作API

Element.classList - Web API 接口参考 | MDN

高性能的网络请求

Fetch API 提供了一个 JavaScript 接口,用于访问和操纵 HTTP 管道的一些具体部分,例如请求和响应。fetch api是基于promise的设计,它是为了取代传统xhr的不合理的写法而生的。

传统网络请求:

fetch网络请求:

fetch() - Web API 接口参考 | MDN

formidable - npm

创建后端

koa2 -e koa-server

cd koa-server

npm install

npm install koa-cors

npm install formidable

进入到koa-server/app.js

添加:const cors = require("koa-cors")

app.use(cors())

index.js

const router = require('koa-router')()
const {formidable} = require('formidable')router.get('/', async (ctx, next) => {ctx.body = {status: 'koa2'}
})router.post('/add',(ctx,next)=>{let body=ctx.request.bodyconsole.log(body)// console.log(ctx.request.body.name)ctx.body ={status: 'success'}
})router.post('/upload',async(ctx,next)=>{let form=formidable({uploadDir:__dirname,keepExtensions:true})await new Promise((resolve,reject)=>{form.parse(ctx.req,(err,fields,files)=>{if(err){reject(err)return}console.log(fields)console.log(files)ctx.set('Content-type','application/json')ctx.status=200ctx.state={fields,files}ctx.body=JSON.stringify(ctx.state,null,2)resolve()})})})router.get('/string', async (ctx, next) => {ctx.body = 'koa2 string'
})router.get('/json', async (ctx, next) => {ctx.body = {title: 'koa2 json'}
})module.exports = router

前端页面

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><input type="file" id="file" />
</body>
<script>fetch('http://localhost:3000/',{method: 'GET',// body:JSON.stringify({})   get请求不需要bodymode: 'cors'})// 服务端返回的数据格式  json()  text()  blob().then(res => res.json())// 服务端接受数据.then(data => {console.log(data)})fetch('http://localhost:3000/add',{method: 'POST',body:JSON.stringify({name:'张三'}),mode: 'cors'}).then(res => res.json()).then(data => {console.log(data)})const file = document.querySelector('#file');file.onchange = function () {// console.log(file.files)let uploadFile = file.files[0];let formData = new FormData();formData.append('file',uploadFile);fetch('http://localhost:3000/upload',{method: 'POST',body:formData,mode: 'cors'}).then(res => res.json()).then(data => {console.log(data)})}
</script>
</html>
高性能的动画处理

Window:requestAnimationFrame() 方法 - Web API 接口参考 | MDN

<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><input type="file" id="file" />
</body>
<script>fetch('http://localhost:3000/',{method: 'GET',// body:JSON.stringify({})   get请求不需要bodymode: 'cors'})// 服务端返回的数据格式  json()  text()  blob().then(res => res.json())// 服务端接受数据.then(data => {console.log(data)})fetch('http://localhost:3000/add',{method: 'POST',body:JSON.stringify({name:'张三'}),mode: 'cors'}).then(res => res.json()).then(data => {console.log(data)})const file = document.querySelector('#file');file.onchange = function () {// console.log(file.files)let uploadFile = file.files[0];let formData = new FormData();formData.append('file',uploadFile);fetch('http://localhost:3000/upload',{method: 'POST',body:formData,mode: 'cors'}).then(res => res.json()).then(data => {console.log(data)})}
</script>
</html>
视频演示

fetch请求和高性能动画处理

js语言层级优化(减少页面中的dom操作)

对比前,有很多的dom操作,并且直接写在循环里面了

优化:把它们转存一下

http://www.yayakq.cn/news/328349/

相关文章:

  • 做一个人网站需要注意什么网站设计需求表
  • 嘉兴网站快照优化公司邵东网页定制
  • 深圳做网站要多手机设计logo软件免费
  • 亦庄建设局网站购物网站开发教程 视频
  • 企业建设网站的需求分析九狐建设网站
  • 网站建站请示有没有帮忙做推广的网站
  • 山西手机网站建设关于做暧暧的网站
  • 制作一个简单网站海南工程建设招标网
  • 网站设计与建设ppt网站建设的预算
  • 北京网站手机站建设公司吗北京互联网公司大厂有哪些
  • 柳州住房和城乡建设局网站wordpress 下载按钮
  • 做韦恩图网站seo外链友情链接
  • 卡片式网站模板免费咨询义诊
  • 免费.网站最新域名小程序模板开发教程
  • WordPress交互式网站wordpress windows 10
  • 网站做收录什么方法快网站建设技能考试试题
  • 网站建设个一般需要花费多少钱关键词排名零芯互联关键词
  • 大连市网站推广公司做耳机套的网站
  • 如何免费建设网站linux 搭建wordpress
  • 天津公司网站建设xampp 开发网站
  • 信息产业部备案网站番号网站怎么做
  • 自己做的网站怎么改电话备案网站有哪些资料
  • 做网站撘框架企业网页有免费的吗
  • 安卓手机网站开发工具建站之星视频
  • 鹿泉网站制作公司口碑好的微信网站建设
  • 公司微网站怎么做的好专业做网站app的公司有哪些
  • 英文网站建设easy网站开发工作难吗
  • 微网站制作工具有哪些找做网站的客户
  • 小学学校网站设计模板网络规划设计师 最高分
  • 专做特产的网站分销网站手机模板