/**
?*?判斷類型
?*/
function?type(data)?{
??let?toString?=?Object.prototype.toString;
??let?dataType?=
????data?instanceof?Element
????????"element"
??????:?toString
??????????.call(data)
??????????.replace(/\[object\s(.+)\]/,?"$1")
??????????.toLowerCase();
??return?dataType;
}
export?default?{
??install(Vue)?{
????Vue.prototype.Global?=?{? type?};
??}
};
//全局配置好后在頁面中使用:
this.Global.type('a') // stringtype(1) // number
this.Global.type(window) // window
this.Global.type(document.querySelector('h1')) // element