let UtilsTools = null;
class Utils {
options: any = null;
constructor(options) {
this.options = options;
}
// 去除字符串空格
removeStringSpace(str: string): string {
return str.replace(/\s*/g, '');
}
getCookie(name: string): string {
const v = window.document.cookie.match('(^|;) ?' + name + '=([^;]*)(;|$)');
return v ? v[2] : null;
}
}
export { UtilsTools };
export default {
async install(Vue: any, options: any) { // eslint-disable-line
UtilsTools = await new Utils(options);
Vue.config.globalProperties.$UtilsTools = UtilsTools;
},
};
在main.ts引用
// 引入
import utilsTools from './utilsTools';
// 挂载
createApp(App).use(utilsTools)
// 使用
$UtilsTools.getCookie()