深克隆
*Object.prototype.toString()
办法,会返回一个形如 "[object XXX]"
的字符串
万物皆对象,.call 继承对象的 toString 办法 *
function typeOf(obj){
const toString = Object.prototype.toString
const map = {'[object Boolean]':'boolean',
'[object Number]':'number',
'[object String]':'string',
'[object Function]':'function',
'[object Array]':'array',
'[object Date]':'date',
'[object RegExp]':'regExp',
'[object Undefined]':'undefined',
'[object Null]':'null',
'[object Object]':'object'
}
return map[toString.call(obj)]
}
//deepCopy
function deepCopy(data){const t = typeOf(data)
let o;
if(t==='array'){o = []
for(let i = 0;i<data.length;i++){o.push(deepCopy(data[i]))
}
}else if(t === 'object'){o = {}
for(let key in data){o[key] = deepCopy(data[key])
}
}else{return data}
return o
}
vue 中类名的依据条件动态显示
class 属性(数组语法) , 对象内如果右侧满足, 则有这个 class 名称 类名是依据右侧的条件满足,则存在
<label :class="wrapClasses"></label>
computed:{wrapClasses(){
return [`${prefixCls}-wrapper`,
{[`${prefixCls}-group-item`]:this.group,
[`${prefixCls}-wrapper-checked`]:this.currentValue,
[`${prefixCls}-wrapper-disabled`]:this.disabled,
[`${prefixCls}-${this.size}`]:!!this.size
}
]
}
}