Skip to content

Commit

Permalink
feat(vuejs): add mixin to handle title property on views
Browse files Browse the repository at this point in the history
  • Loading branch information
hbollon committed Jul 18, 2021
1 parent fae88b1 commit 2afcf8e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions resources/static/vue-igopher/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import astor from "@/plugins/astilectron";
import titleMixin from "@/mixins/titleMixin";

import mitt, { Emitter } from 'mitt';
const emitter: Emitter = mitt();
Expand All @@ -17,5 +18,6 @@ app
debug: true,
emitter: emitter
})
.mixin(titleMixin)
.use(router)
.mount("#app");
17 changes: 17 additions & 0 deletions resources/static/vue-igopher/src/mixins/titleMixin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Mixin used to dynamically manage page title for each vue views */

function getTitle(vm: any) {
const title = vm.$options;
if (title) {
return typeof title === "function" ? title.call(vm) : title;
}
}

export default {
mounted() {
const title = getTitle(this);
if (title) {
document.title = "IGopher - " + title.title;
}
},
};
1 change: 1 addition & 0 deletions resources/static/vue-igopher/src/views/DmAutomation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as config from "@/config"
import { Astor } from "@/plugins/astilectron";
@Options({
title: "DM Automation",
components: {
DmAutomationPanel,
},
Expand Down
1 change: 1 addition & 0 deletions resources/static/vue-igopher/src/views/Logs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Pager {
}
@Options({
title: "Logs",
components: {
LogsPanel,
},
Expand Down
1 change: 1 addition & 0 deletions resources/static/vue-igopher/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as config from "@/config"
import { Astor } from "@/plugins/astilectron";
@Options({
title: "Settings",
components: {
SettingsPanel,
},
Expand Down

0 comments on commit 2afcf8e

Please sign in to comment.