大杂烩: 踩坑记录
這個(gè)時(shí)候, 使用 !getQueryVariable('platform') 判斷, 無論怎樣都是走else里,因?yàn)槿》吹氖?字符串 , 字符串取反肯定是false,只有空字符串取反才是true。
修改成:
!JSON.parse(getQueryVariable('platform')) 或者 !!getQueryVariable('platform')
打印出:
所以以后再判斷的時(shí)候,可以用typeOf去看看是什么類型
對(duì)象obj中取值
const obj = {a:1,b:2,c:3,d:4,e:5, }//用ES6的解構(gòu)賦值來取值 const {a,b,c,d,e} = obj; const f = a + d; const {a:a1} = obj; console.log(a1);// 1合并數(shù)據(jù)
const a = [1,2,3]; const b = [1,5,6]; const c = a.concat(b);//[1,2,3,1,5,6]const obj1 = {a:1, } const obj2 = {b:1, } const obj = Object.assign({}, obj1, obj2);//{a:1,b:1}if中判斷條件
if(type == 1 ||type == 2 ||type == 3 ||type == 4 || ){//... }// ES6中數(shù)組實(shí)例方法includes const condition = [1,2,3,4];if( condition.includes(type) ){//... }列表搜索
// find方法中找到符合條件的項(xiàng),就不會(huì)繼續(xù)遍歷數(shù)組 性能好 const a = [1,2,3,4,5]; const result = a.find( item => item === 3)獲取對(duì)象屬性值
可選鏈操作符
添加對(duì)象屬性
let obj = {}; let index = 1; obj[`topic${index}`] = '話題內(nèi)容';輸入框非空的判斷
if(value !== null && value !== undefined && value !== ''){//... } // ES6中新出的空值合并運(yùn)算符 // 空值合并運(yùn)算符 ?? 當(dāng)左側(cè)操作數(shù)為 null 或 undefined 時(shí),其返回右側(cè)的操作數(shù)。否則返回左側(cè)的操作數(shù)。 if(value ?? '' !== ''){//... }會(huì)引起元素位置變化的就會(huì)reflow(回流),如,窗口大小改變、字體大小改變、以及元素位置改變,都會(huì)引起周圍的元素改變他們以前的位置;
不會(huì)引起位置變化的,只是在以前的位置進(jìn)行改變背景顏色等,只會(huì)repaint(重繪)
回流必將引起重繪,重繪不一定會(huì)引起回流。
回流比重繪的代價(jià)要更高
JS加法精度問題
function add_sum(arg1, arg2) {var r1, r2, m;try {r1 = arg1.toString().split(".")[1].length;} catch (e) {r1 = 0;}try {r2 = arg2.toString().split(".")[1].length;} catch (e) {r2 = 0;}m = Math.pow(10, Math.max(r1, r2));return (arg1 * m + arg2 * m) / m; }總結(jié)
- 上一篇: vue 父组件传子组件数值,父值变更子获
- 下一篇: sudo: apt-get:找不到命令”