zoukankan      html  css  js  c++  java
  • js代码片段

      1 {
      2   "serizlize": {
      3     "prefix": "seri",
      4     "body": "serialize"
      5   },
      6   "bodyParser": {
      7     "prefix": "body-parser",
      8     "body": [
      9       "const bodyParser = require('body-parser');",
     10       "app.use(bodyParser.urlencoded({extended:false}));"
     11     ]
     12   },
     13   "art-template": {
     14     "prefix": "art",
     15     "body": [
     16       "//告诉express框架模板所在的位置",
     17       "app.set('views',path.join(__dirname,'views'));",
     18       "//告诉express框架模板的默认后缀是什么",
     19       "app.set('view engine','art');",
     20       "//当渲染后缀为art的模板时,所使用的模板引擎是什么",
     21       "app.engine('art',require('express-art-template'));"
     22     ]
     23   },
     24   "console.log": {
     25     "prefix": "clg",
     26     "body": [
     27       "console.log($1)"
     28     ]
     29   },
     30   "e.stop": {
     31     "prefix": "e.stop",
     32     "body": "e.stopPropagation()"
     33   },
     34   "enctype": {
     35     "prefix": "enctype",
     36     "body": "'application/x-www-form-urlencoded'"
     37   },
     38   "react": {
     39     "prefix": "react",
     40     "body": [
     41       "import React,{Component} from 'react'
    ",
     42       "export default class $1 extends Component{
    ",
     43       "  constructor(){
    ",
     44       "    super()
    ",
     45       "    this.state = {}
    ",
     46       "  }
    ",
     47       "  render(){
    ",
     48       "    return (
    ",
     49       "      <div>$1</div>
    ",
     50       "    )
    ",
     51       "  }
    ",
     52       "} "
     53     ],
     54     "description": "react"
     55   },
     56   "Mongoose Connect": {
     57     "prefix": "mongo",
     58     "body": [
     59       "//连接mongodb数据库",
     60       "const mongoose = require("mongoose");",
     61       "mongoose",
     62       "  .connect('mongodb://localhost/${1:数据库的名字}',{useNewUrlParser: true,useUnifiedTopology:true})",
     63       "  .then(() => console.log("数据库连接成功"))",
     64       "  .catch(err => console.log("数据库连接失败"));"
     65     ],
     66     "description": "mongodb连接数据库"
     67   },
     68   "schema": {
     69     "prefix": "jihe",
     70     "body": [
     71       "//集合规则",
     72       "var guize = new mongoose.Schema({",
     73       "	name:String,",
     74       "	age:Number",
     75       "});",
     76       "",
     77       "//创建文档的构造函数,前后两个单词规范的写法都是首字母大写",
     78       "//mongoose的实现方式:当你根据如下的构造函数创建文档对象的时候,在数据库中的集合自动会有一个persons的集合",
     79       "const Person = mongoose.model('Person',guize);"
     80     ]
     81   },
     82   "qs": {
     83     "prefix": "qs",
     84     "body": [
     85       "document.querySelector('${2:selector}')"
     86     ]
     87   },
     88   "qsa": {
     89     "prefix": "qsa",
     90     "body": [
     91       "document.querySelectorAll('${2:selector}')"
     92     ]
     93   },
     94   "xyljq": {
     95     "prefix": "xyljq",
     96     "description": "",
     97     "body": [
     98       "//axios响应拦截器",
     99       "axios.interceptors.response.use(function(res){",
    100       "	return res;//响应回来的数据",
    101       "},function(error){",
    102       "	console.log(error)",
    103       "})"
    104     ]
    105   },
    106   "qqljq": {
    107     "prefix": "qqljq",
    108     "description": "",
    109     "body": [
    110       "//axios请求拦截器",
    111       "axios.interceptors.request.use(function(config){",
    112       "	return config;//请求头配置项",
    113       "},function(error){",
    114       "	console.log(error)",
    115       "})"
    116     ]
    117   },
    118   "requiredfield": {
    119     "prefix": "required_field",
    120     "body": [
    121       "{required:true,message:'请输入',trigger:'blur'}"
    122     ]
    123   },
    124   "id": {
    125     "prefix": "gid",
    126     "body": "document.getElementById('$1')"
    127   },
    128   "tag": {
    129     "prefix": "gtag",
    130     "body": "document.getElementsByTagName('$1')"
    131   },
    132   "ajax": {
    133     "prefix": "$.ajax",
    134     "body": [
    135       "$.ajax({",
    136       "	type:'${1:get}',",
    137       "	url:'$2',",
    138       "	success:function(res){",
    139       "		$3",
    140       "	}",
    141       "})"
    142     ]
    143   },
    144   "mysql_lianjie": {
    145     "prefix": "mysql_lianjie",
    146     "body": [
    147       "const mysql = require('mysql')",
    148       "const db = mysql.createPool({",
    149       "	host:'127.0.0.1',//数据库的ip地址",
    150       "	user:'root',//登录数据库的账号",
    151       "	password:'admin123',//登录数据库的密码",
    152       "	database:'$1'//指定要操作哪个数据库",
    153       "})"
    154     ]
    155   },
    156   "express": {
    157     "prefix": "express",
    158     "description": "",
    159     "body": [
    160       "const express = require('express')",
    161       "const app = express()",
    162       "",
    163       "app.listen(80,()=>{",
    164       "    console.log('服务器创建成功,运行在http://127.0.0.1')",
    165       "})",
    166       "",
    167       ""
    168     ]
    169   },
    170   "fwq": {
    171     "prefix": "fwq",
    172     "description": "",
    173     "body": [
    174       "const express = require('express')",
    175       "const app = express()",
    176       "",
    177       "app.listen(80,()=>{",
    178       "    console.log('服务器创建成功,运行在http://127.0.0.1')",
    179       "})",
    180       ""
    181     ]
    182   },
    183   "sjk": {
    184     "prefix": "sjk",
    185     "description": "",
    186     "body": [
    187       "const mysql = require('mysql')",
    188       "var db = mysql.createPool({",
    189       "    host:'127.0.0.1',",
    190       "    user:'root',",
    191       "    password:'',",
    192       "    database:''",
    193       "})",
    194       ""
    195     ]
    196   },
    197   "baocuo": {
    198     "prefix": "baocuo",
    199     "description": "",
    200     "body": [
    201       "if (res.meta.status !== 200) return this.$$message.error('获取失败')"
    202     ]
    203   },
    204   "http": {
    205     "prefix": "http",
    206     "description": "",
    207     "body": [
    208       "const {data:res} = await this.$$http.get('')",
    209       "if (res.meta.status !== 200) return this.$$message.error('获取数据失败')",
    210       ""
    211     ]
    212   },
    213   "node_day1_shizhong": {
    214     "prefix": "node_day1_shizhong
    ",
    215     "description": "",
    216     "body": [
    217       "/* eslint-disable */
    ",
    218       "
    ",
    219       "/* eslint-disable */
    ",
    220       "
    ",
    221       "// 1.1 导入 fs 模块
    ",
    222       "const fs = require('fs')
    ",
    223       "// 1.2 导入 path 模块
    ",
    224       "const path = require('path')
    ",
    225       "
    ",
    226       "// 1.3 定义正则表达式,分别匹配 <style></style> 和 <script></script> 标签
    ",
    227       "const regStyle = /<style>[\s\S]*<\/style>/
    ",
    228       "const regScript = /<script>[\s\S]*<\/script>/
    ",
    229       "
    ",
    230       "// 2.1 调用 fs.readFile() 方法读取文件
    ",
    231       "fs.readFile(path.join(__dirname, '../素材/index.html'), 'utf8', function(err, dataStr) {
    ",
    232       "  // 2.2 读取 HTML 文件失败
    ",
    233       "  if (err) return console.log('读取HTML文件失败!' + err.message)
    ",
    234       "  // 2.3 读取文件成功后,调用对应的三个方法,分别拆解出 css, js, html 文件
    ",
    235       "  resolveCSS(dataStr)
    ",
    236       "  resolveJS(dataStr)
    ",
    237       "  resolveHTML(dataStr)
    ",
    238       "})
    ",
    239       "
    ",
    240       "// 3.1 定义处理 css 样式的方法
    ",
    241       "function resolveCSS(htmlStr) {
    ",
    242       "  // 3.2 使用正则提取需要的内容
    ",
    243       "  const r1 = regStyle.exec(htmlStr)
    ",
    244       "  // 3.3 将提取出来的样式字符串,进行字符串的 replace 替换操作
    ",
    245       "  const newCSS = r1[0].replace('<style>', '').replace('</style>', '')
    ",
    246       "  // 3.4 调用 fs.writeFile() 方法,将提取的样式,写入到 clock 目录中 index.css 的文件里面
    ",
    247       "  fs.writeFile(path.join(__dirname, './clock/index.css'), newCSS, function(err) {
    ",
    248       "    if (err) return console.log('写入 CSS 样式失败!' + err.message)
    ",
    249       "    console.log('写入样式文件成功!')
    ",
    250       "  })
    ",
    251       "}
    ",
    252       "
    ",
    253       "// 4.1 定义处理 js 脚本的方法
    ",
    254       "function resolveJS(htmlStr) {
    ",
    255       "  // 4.2 通过正则,提取对应的 <script></script> 标签内容
    ",
    256       "  const r2 = regScript.exec(htmlStr)
    ",
    257       "  // 4.3 将提取出来的内容,做进一步的处理
    ",
    258       "  const newJS = r2[0].replace('<script>', '').replace('</script>', '')
    ",
    259       "  // 4.4 将处理的结果,写入到 clock 目录中的 index.js 文件里面
    ",
    260       "  fs.writeFile(path.join(__dirname, './clock/index.js'), newJS, function(err) {
    ",
    261       "    if (err) return console.log('写入 JavaScript 脚本失败!' + err.message)
    ",
    262       "    console.log('写入 JS 脚本成功!')
    ",
    263       "  })
    ",
    264       "}
    ",
    265       "
    ",
    266       "// 5.1 定义处理 HTML 结构的方法
    ",
    267       "function resolveHTML(htmlStr) {
    ",
    268       "  // 5.2 将字符串调用 replace 方法,把内嵌的 style 和 script 标签,替换为外联的 link 和 script 标签
    ",
    269       "  const newHTML = htmlStr.replace(regStyle, '<link rel="stylesheet" href="./index.css" />').replace(regScript, '<script src="./index.js"></script>')
    ",
    270       "  // 5.3 写入 index.html 这个文件
    ",
    271       "  fs.writeFile(path.join(__dirname, './clock/index.html'), newHTML, function(err) {
    ",
    272       "    if (err) return console.log('写入 HTML 文件失败!' + err.message)
    ",
    273       "    console.log('写入 HTML 页面成功!')
    ",
    274       "  })
    ",
    275       "}
    ",
    276       ""
    277     ]
    278   },
    279   "node_day01_shizhong": {
    280     "prefix": "node_day01_shizhong
    ",
    281     "description": "",
    282     "body": [
    283       "/* eslint-disable */
    ",
    284       "
    ",
    285       "// 1.1 导入 http 模块
    ",
    286       "const http = require('http')
    ",
    287       "// 1.2 导入 fs 模块
    ",
    288       "const fs = require('fs')
    ",
    289       "// 1.3 导入 path 模块
    ",
    290       "const path = require('path')
    ",
    291       "
    ",
    292       "// 2.1 创建 web 服务器
    ",
    293       "const server = http.createServer()
    ",
    294       "// 2.2 监听 web 服务器的 request 事件
    ",
    295       "server.on('request', (req, res) => {
    ",
    296       "  // 3.1 获取到客户端请求的 URL 地址
    ",
    297       "  //     /clock/index.html
    ",
    298       "  //     /clock/index.css
    ",
    299       "  //     /clock/index.js
    ",
    300       "  const url = req.url
    ",
    301       "  // 3.2 把请求的 URL 地址映射为具体文件的存放路径
    ",
    302       "  // const fpath = path.join(__dirname, url)
    ",
    303       "  // 5.1 预定义一个空白的文件存放路径
    ",
    304       "  let fpath = ''
    ",
    305       "  if (url === '/') {
    ",
    306       "    fpath = path.join(__dirname, './clock/index.html')
    ",
    307       "  } else {
    ",
    308       "    //     /index.html
    ",
    309       "    //     /index.css
    ",
    310       "    //     /index.js
    ",
    311       "    fpath = path.join(__dirname, '/clock', url)
    ",
    312       "  }
    ",
    313       "
    ",
    314       "  // 4.1 根据“映射”过来的文件路径读取文件的内容
    ",
    315       "  fs.readFile(fpath, 'utf8', (err, dataStr) => {
    ",
    316       "    // 4.2 读取失败,向客户端响应固定的“错误消息”
    ",
    317       "    if (err) return res.end('404 Not found.')
    ",
    318       "    // 4.3 读取成功,将读取成功的内容,响应给客户端
    ",
    319       "    res.end(dataStr)
    ",
    320       "  })
    ",
    321       "})
    ",
    322       "// 2.3 启动服务器
    ",
    323       "server.listen(80, () => {
    ",
    324       "  console.log('server running at http://127.0.0.1')
    ",
    325       "})
    ",
    326       ""
    327     ]
    328   },
    329   "node_express_zhongjianjian": {
    330     "prefix": "node_express_zhongjianjian",
    331     "description": "",
    332     "body": [
    333       "中间件的分类:",
    334       "1. 应用级别的中间件",
    335       "2. 路由级别的中间件",
    336       "3. 错误级别的中间件",
    337       "4. express内置的中间件",
    338       "    + express.static",
    339       "    + express.json",
    340       "    + express.urlencoded",
    341       "5. 第三方的中间件",
    342       "",
    343       ""
    344     ]
    345   },
    346   "node_kuayu": {
    347     "prefix": "node_kuayu",
    348     "description": "",
    349     "body": [
    350       "Accept、Accept-Language、Content-Language、DPR、Downlink、Save-Data、Viewport-Width、Width 、",
    351       "Content-Type (值仅限于 text/plain、multipart/form-data、application/x-www-form-urlencoded ",
    352       "",
    353       "Access-Control-Allow-Origin ",
    354       "Access-Control-Allow-Headers ",
    355       "Access-Control-Allow-Methods ",
    356       "",
    357       "简单请求:",
    358       "1. 同时满足以下两大条件的请求,就属于简单请求:",
    359       "    + 请求方式:GET、POST、HEAD 三者之一",
    360       "    + HTTP 头部信息不超过以下几种字段:无自定义头部字段、Accept、Accept-Language、Content-Language、DPR、",
    361       "    Downlink、Save-Data、Viewport-Width、Width 、Content-Type(只有三个值application/x-www-form-",
    362       "    urlencoded、multipart/form-data、text/plain)",
    363       "2. 简单请求的特点:客户端与服务器之间只会发生一次请求",
    364       "",
    365       "",
    366       "预检请求",
    367       "只要符合以下任何一个条件的请求,都需要进行预检请求:",
    368       "1. 请求方式为 GET、POST、HEAD 之外的请求 Method 类型",
    369       "2. 请求头中包含自定义头部字段",
    370       "3. 向服务器发送了 application/json 格式的数据",
    371       "在浏览器与服务器正式通信之前,浏览器会先发送 OPTION 请求进行预检,以获知服务器是否允许该实际请求,所以这一",
    372       "次的 OPTION 请求称为“预检请求”。服务器成功响应预检请求后,才会发送真正的请求,并且携带真实数据",
    373       "预检请求的特点:OPTION 预检请求成功之后,才会发起真正的请求。",
    374       "",
    375       "jsonp ",
    376       "浏览器端通过 <script> 标签的 src 属性,请求服务器上的数据,同时,服务器返回一个函数的调用。这种请求数据",
    377       "的方式叫做 JSONP",
    378       "特点:JSONP 仅支持 GET 请求,不支持 POST、PUT、DELETE 等请求",
    379       "",
    380       ""
    381     ]
    382   },
    383   "node_shujukugainian": {
    384     "prefix": "node_shujukugainian",
    385     "description": "",
    386     "body": [
    387       "在传统型数据库中,数据的组织结构分为数据库(database)、数据表(table)、数据行(row)、字段(field)这 4 大部分组成",
    388       "",
    389       ""
    390     ]
    391   },
    392   "node_day_xuanruan": {
    393     "prefix": "node_day_xuanruan",
    394     "description": "",
    395     "body": [
    396       "服务端渲染的优缺点",
    397       "优点:",
    398       "前端耗时少。因为服务器端负责动态生成 HTML 内容,浏览器只需要直接渲染页面即可。尤其是移动端,更省电。",
    399       "有利于SEO。因为服务器端响应的是完整的 HTML 页面内容,所以爬虫更容易爬取获得信息,更有利于",
    400       "",
    401       ".缺点:",
    402       "占用服务器端资源。即服务器端完成 HTML 页面内容的拼接,如果请求较多,会对服务器造成一定的访问压力。",
    403       "不利于前后端分离,开发效率低。使用服务器端渲染,则无法进行分工合作,尤其对于前端复杂度高的项目,不利于",
    404       "项目高效开发。",
    405       "",
    406       "",
    407       "前后端分离的 Web 开发模式",
    408       "前后端分离的概念:前后端分离的开发模式,依赖于 Ajax 技术的广泛应用。即后端不提供完整的 HTML 页面内容,而",
    409       "是提供一些 API 接口,使得前端可以获取到 json 数据;然后前端通过 Ajax 调用后端提供的 API 接口,拿到 json 数据",
    410       "之后再在前端进行 HTML 页面的拼接,最终展示在浏览器上",
    411       "简而言之,前后端分离的 Web 开发模式,就是后端只负责提供 API 接口,前端使用 Ajax 调用接口的开发模式。",
    412       "",
    413       "前后端分离的优缺点",
    414       "",
    415       "优点",
    416       "开发体验好。前端专注于 UI 页面的开发,后端专注于api 的开发,且前端有更多的选择性。",
    417       "用户体验好。Ajax 技术的广泛应用,极大的提高了用户的体验,可以轻松实现页面的局部刷新。",
    418       "减轻了服务器端的渲染压力。因为页面最终是在每个用户的浏览器中生成的",
    419       "",
    420       "缺点 ",
    421       "不利于 SEO。因为完整的 HTML 页面需要在客户端动态拼接完成,所以爬虫对无法爬取页面的有效信息。(解决方",
    422       "案:利用 Vue、React 等前端框架的 SSR (server side render)技术能够很好的解决 SEO 问题",
    423       ""
    424     ]
    425   },
    426   "node_http_xieyi": {
    427     "prefix": "node_http_xieyi
    ",
    428     "description": "",
    429     "body": [
    430       "/* eslint-disable */
    ",
    431       "
    ",
    432       "# http协议
    ",
    433       "- 二台电脑 一台是客户端 一台是服务器 客户端和服务器在通信
    ",
    434       "- 本质就是二台电脑在交互
    ",
    435       "- 提前规定好了什么东西代表,有一套规范在里面,必须严格按这个规范来传递消息,要不然双方不知道对方在说什么
    ",
    436       "    1. 提前规定好
    ",
    437       "    2. 严格按这个格式去发消息
    ",
    438       "- http协议
    ",
    439       "    + 传的是超文本的东西 只有文本、还有图片、视频、音频
    ",
    440       "        + 超文本 html
    ",
    441       "- http协议
    ",
    442       "    + 客户端向服务器传递东西 请求相关的东西 请求报文
    ",
    443       "    + 服务器向客户端传递的东西 响应相关的东西 响应报文
    ",
    444       "- 报文不能随便写 格式严格提前约定好
    ",
    445       "- 所谓掌握http协议指的就是了解请求报文格式、响应报文格式长什么样子
    ",
    446       "- 想办法看原始报文
    ",
    447       "    + 请求报文
    ",
    448       "        + 请求行
    ",
    449       "            + 请求方式(get,post) url 协议版本(http1.1)
    ",
    450       "        + 请求头
    ",
    451       "            + 组成格式是:键:值
    ",
    452       "            + Content-Type:
    ",
    453       "                + 告诉服务器请求体的格式长什么样子 
    ",
    454       "                    + application/x-www-form-urlencoded 打包成一个整体
    ",
    455       "                    + multipart/form-data 一个一个发送 
    ",
    456       "        + 请求体
    ",
    457       "            + 只有post才会请求体
    ",
    458       "            + 就是查询参数
    ",
    459       "            + xhr.send('username=zs&age=20')
    ",
    460       "    + 响应报文
    ",
    461       "        + 状态行
    ",
    462       "            + 状态码
    ",
    463       "                电脑出问题了 黑屏 按电源键 主板坏了 响一声 二声 
    ",
    464       "                有 200 没有 404  
    ",
    465       "                200 成功
    ",
    466       "                404 找不到
    ",
    467       "                500 服务器出问题 
    ",
    468       "                304 走缓存
    ",
    469       "                
    ",
    470       "        + 响应头
    ",
    471       "            + 告诉客户端这个数据是什么类型的数据
    ",
    472       "        + 响应体
    ",
    473       "            + html代码、css代码\图片、ajax返回的数据
    ",
    474       "
    ",
    475       "    + 请求头可以用来告诉服务器请求体的数据长什么样子的
    ",
    476       "    + 响应头是用来告诉客户端响应体数据长什么样子的
    ",
    477       "
    ",
    478       ""
    479     ]
    480   },
    481   "error": {
    482     "prefix": "error_msg",
    483     "description": "",
    484     "body": [
    485       "if(res.meta.status !== 200)return this.$$message.error('$1')"
    486     ]
    487   }
    488 }
  • 相关阅读:
    使用IDEA打包出现“Cleaning up unclosed ZipFile for archive”错误
    Kafka读取本地文件作为生产者
    Redis连接池
    如果javaapi长时间消费不到数据
    Redis 持久化的两种方式
    kafka结合streaming的两种方式
    二分法查找
    shell脚本学习
    Md5Utils
    idea添加jar包
  • 原文地址:https://www.cnblogs.com/ndh074512/p/14995323.html
Copyright © 2011-2022 走看看