mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 00:03:07 +00:00
Advent22 typescript plugin
This commit is contained in:
parent
f585b5f90c
commit
c1ea31f874
5 changed files with 46 additions and 2 deletions
|
@ -22,7 +22,7 @@ export default class CalendarDoor extends Vue {
|
||||||
modal_visible = false;
|
modal_visible = false;
|
||||||
|
|
||||||
private get image_url(): string {
|
private get image_url(): string {
|
||||||
return "http://localhost:8000/api/days/picture/" + this.day;
|
return this.$advent22.api_url("days/picture/" + this.day);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
10
ui/src/d.ts/shims-advent22.d.ts
vendored
Normal file
10
ui/src/d.ts/shims-advent22.d.ts
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
import { Advent22 } from "@/plugins/advent22";
|
||||||
|
|
||||||
|
declare module "@vue/runtime-core" {
|
||||||
|
// bind to `this` keyword
|
||||||
|
interface ComponentCustomProperties {
|
||||||
|
$advent22: Advent22;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { };
|
|
@ -1,6 +1,10 @@
|
||||||
|
import { Advent22Plugin } from "@/plugins/advent22"
|
||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
|
|
||||||
import "bulma/css/bulma.css"
|
import "bulma/css/bulma.css"
|
||||||
|
|
||||||
createApp(App).mount('#app')
|
const app = createApp(App)
|
||||||
|
app.use(Advent22Plugin)
|
||||||
|
|
||||||
|
app.mount('#app')
|
||||||
|
|
30
ui/src/plugins/advent22.ts
Normal file
30
ui/src/plugins/advent22.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { App, Plugin } from 'vue';
|
||||||
|
|
||||||
|
export class Advent22 {
|
||||||
|
private get api_baseurl(): string {
|
||||||
|
// in production mode, return "//host/api"
|
||||||
|
if (process.env.NODE_ENV === "production") {
|
||||||
|
return `//${window.location.host}/api`;
|
||||||
|
|
||||||
|
} else if (process.env.NODE_ENV !== "development") {
|
||||||
|
// not in prouction or development mode
|
||||||
|
console.warn("Unexpected NODE_ENV value");
|
||||||
|
}
|
||||||
|
|
||||||
|
// in development mode, return "//hostname:8000/api"
|
||||||
|
return `//${window.location.hostname}:8000/api`;
|
||||||
|
}
|
||||||
|
|
||||||
|
public api_url(endpoint?: string): string {
|
||||||
|
if (endpoint === undefined)
|
||||||
|
return `${this.api_baseurl}`;
|
||||||
|
|
||||||
|
return `${this.api_baseurl}/${endpoint}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Advent22Plugin: Plugin = {
|
||||||
|
install(app: App) {
|
||||||
|
app.config.globalProperties.$advent22 = new Advent22();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue