Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 33 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
1 | 1 | import type { ComponentOptionsMixin, CreateComponentPublicInstance } from 'vue'; |
|
2 | 1 | import { isFunction } from './utils'; |
|
3 | 1 | ||
4 | 1 | /** |
|
5 | 1 | * Mixin, to be used in options API |
|
6 | 1 | * Can be used locally or registered globally using `mixin: true` |
|
7 | 1 | */ |
|
8 | 1 | const pageTitleMixin: ComponentOptionsMixin = { |
|
9 | 1 | created(this: CreateComponentPublicInstance) { |
|
10 | 7 | const { title } = this.$options; |
|
11 | 7 | ||
12 | 7 | if (title === undefined) { |
|
13 | 3 | return; |
|
14 | 3 | } |
|
15 | 3 | ||
16 | 3 | // allow use dinamic title system |
|
17 | 7 | if (isFunction(title)) { |
|
18 | 2 | this.$watch( |
|
19 | 2 | () => title.call(this, this), |
|
20 | 2 | (val: string) => { |
|
21 | 3 | this.$setPageTitle(val); |
|
22 | 3 | }, |
|
23 | 2 | { immediate: true } |
|
24 | 2 | ); |
|
25 | 2 | return; |
|
26 | 2 | } |
|
27 | 2 | ||
28 | 2 | this.$setPageTitle(title); |
|
29 | 2 | }, |
|
30 | 7 | }; |
|
31 | 1 | ||
32 | export { pageTitleMixin }; |
||
33 |