Bläddra i källkod

[frontend] Add global web component attribute for hue base URL config

For now just for axios requests
Johan Ahlen 5 år sedan
förälder
incheckning
c3de557958
1 ändrade filer med 15 tillägg och 2 borttagningar
  1. 15 2
      desktop/core/src/desktop/js/vue/webComponentWrapper.ts

+ 15 - 2
desktop/core/src/desktop/js/vue/webComponentWrapper.ts

@@ -1,8 +1,21 @@
-import Vue from 'vue';
+import axios from 'axios';
+import Vue, { ComponentOptions } from 'vue';
 import vueCustomElement from 'vue-custom-element';
 
 Vue.use(vueCustomElement);
 
+export interface HueComponentOptions<T extends Vue> extends ComponentOptions<T> {
+  hueBaseUrl?: string;
+}
+
 export const wrap = <T extends Vue>(tag: string, component: { new (): T }): void => {
-  Vue.customElement(tag, new component().$options);
+  Vue.customElement(tag, new component().$options, {
+    connectedCallback() {
+      const element = <HTMLElement>this;
+      const hueBaseUrl = element.getAttribute('hue-base-url');
+      if (hueBaseUrl) {
+        axios.defaults.baseURL = hueBaseUrl;
+      }
+    }
+  });
 };