Web APIs
window.location.href //整个url
window.location.search //url从?开始的的搜索部分
window.open()
window.location.href = "/metricreport?metric_id=6487e1de" //在本窗口跳转
window.localstorage === localstorage //True
window.history === history
从link取query参数的正确方式:
log(searchParams instanceOf URLSearchParams) //"true" URLSearchParams是js内置对象
"?branch=xxx&id=xxx" ==> URLSearchParams
const searchParams = new URLSearchParams(window.location.search)
const branch_id = searchParams.get("branch")
JS
用async,await的时候,错误处理用
try{
}
catch(error){
}
js默认参数
es6之前-手动处理(在JavaScript中,当一个函数的参数没有被传入时,默认值为undefined)
function query(filter) {
//利用||操作符返回第一个“truthy”值的特性
filter = filter || {}
}
es6支持默认参数
function query(filter={}) {
}
不传第一个参数(用默认值),只传第二个参数,可以给第一个位置传undefined
?.
可选链操作符
actionRef.current?.reload();
判断NaN
NaN == NaN //False
Number.isNaN(NaN) //True
最大整数
Number.MAX_SAFE_INTEGER = 9007199254740991
React
//React响应式变量
let NO_TEMPLATE_METRIC_TYPE = [
METRIC_TYPE.APA_PARKIN_ROADTEST,
METRIC_TYPE.NPOE_SOLVER_PWJ,
METRIC_TYPE.NPOE_LANE_PLAN,
].includes(selectedMetricType)
//selectedMetricType是一个state,NO_TEMPLATE_METRIC_TYPE是一个Boolean,
//依赖于state的变量成为响应式变量,
//selectedMetricType 变化时 NO_TEMPLATE_METRIC_TYPE 也会随之变化
React报错修复:“Uncaught TypeError: destroy is not a function”
报错原因:在useEffect中使用async的返回值问题。
useEffect( fetchChartData(), [])
=>
useEffect(()=>{ fetchChartData() }, [])
Git
git status 上次commit后是否有修改
git pull origin master:devon_dev 拉取远程origin仓库的master,合并到本地devon_dev
git pull origin master 拉取远程origin仓库的master,合并到当前分支
git log devon_dev ^origin/master devon_dev有,而远端master(的本地跟踪分支)没有的log
git checkout -b new_branch 创建new_branch分支,并切换到该分支
git checkout -b devon_dev2 origin/master
git branch devon_dev2 origin/master 从远端master分支创建一个devon_dev2分支
JSON
是一种格式 / 规范
var obj2={};//这只是JS对象
var obj3={width:100,height:200};/*跟JSON不沾边,只是JS的对象 */
var obj4={'width':100,'height':200};/*跟JSON不沾边,只是JS的对象 */
var obj5={"width":100,"height":200,"name":"rose"}; /*符合JSON格式的JavaScript对象 */
var str1='{"width":100,"height":200,"name":"rose"}';/*符合JSON格式的字符串 */
JSON是一个js全局对象
JSON.stringify js对象 => JSON格式字符串
JSON.parse JSON格式字符串 => js对象
直接从表单中获取的字符串是包含\n\t等字符的,而JSON.parse会解析去掉这些。
https://www.cnblogs.com/ilinuxer/p/6869933.html
YAML:YAML vs. JSON: 有什么区别? - 掘金
功能与JSON类似,但使用缩进表示结构。
Regular Expression
RegExp的两种创建方式
1.字面量创建
/pattern模式/ option flags修饰符
/apa/i
2.构造函数创建
new RegExp(pattern, flags)
new RegExp("a"+"pa", "i")
Option Flags
i -- 大小写不敏感;
g -- 全局匹配;
Pattern
[abc] -- 方括号中任一字符
[0-9] -- 0-9中任一数字
(x|y) -- x or y
量词
x{n}
x{n,m}
x* //{0,}
x+ //{1,}
x? //{0,1}
元字符
\d //数字
\s //空白字符
常用方法
RegExp.test(Str)
/aba/i.test("APA_1.5.2") //返回true or false
Str.search(RegExp)
"APA_1.5.2".search(/apa/i) //返回找到的index,没找到返回-1
Mongo
$Regex:
{field: {$regex: pattern, $options: "i"}}
{field: {$regex: /pattern/option}
{name: {$regex: "devon_test"}}
{name: {$regex: /devon_test/i}}
$in是一个逻辑 OR 操作符,匹配字段值等于指定数组中任何值的文档
$all是一个逻辑 AND 操作符,匹配字段值包含指定数组中所有元素的文档
{id: {$in: [id1, id2, id3]}}
{id: {$all: [id1, id2, id3]}}
CSS
内联css也可以用%,但是要用str
left: '10%',
left: 10,