Skip to content

Commit 608a30b

Browse files
author
Artur Mędrygał
committed
global computed $var
1 parent 03563d8 commit 608a30b

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,19 @@ module.exports = (options = {}) => ({
22
async extendPageData($page) {
33
$page.global = options.variables || {}
44
},
5+
enhanceAppFiles() {
6+
return [
7+
{
8+
name: 'global-variable',
9+
content: `
10+
export default ({ Vue }) => { Vue.mixin({
11+
computed: {
12+
$var() {
13+
return this.$page.global
14+
}
15+
}
16+
}) }`.trim(),
17+
},
18+
]
19+
},
520
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuepress-plugin-global-variables",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"main": "index.js",
55
"author": "Artur Mędrygał",
66
"license": "MIT",

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ module.exports = {
2525
}
2626
```
2727

28-
Now, you can simply use `this.$page.global[key]` to get your variable in any template or component.
28+
Now, you can simply use `$var[key]` or `this.$page.global[key]` to get your variable in any template or component.
2929

3030
Example:
3131

3232
```vue
33+
{{ $var.example }}
34+
35+
// or
36+
3337
{{ $page.global.example }}
3438
```
3539

0 commit comments

Comments
 (0)