解决问题
vue插件+单例模式
export class RetroPlugin {
/**核心 - 一个接收实例的静态成员 */
private static instance: RetroPlugin;
/**核心 - 私有构造函数 */
private constructor(options: any) {
this.install(Vue, options)
}
/**核心 - 获取实例 */
static getInstance(options: any) {
if (this.instance == null) {
this.instance = new RetroPlugin(options);
}
return this.instance
}
static getAxios(): void {
return Vue.prototype.$axios
}
public install(Vue: any, options: any): void {
if (options) {
Vue.prototype.$axios = axios.create(options);
}
}
}
Vue.use(RetroPlugin.getInstance({
baseURL: 'https://cnodejs.org/api',
timeout: 1000,
headers: {
'X-Custom-Header': 'foobar'
}
}))