Skip to content

Commit 9c947b2

Browse files
committed
feat: Vue.$vuepress & Vue.prototype.$vuepress
1 parent a78a91f commit 9c947b2

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

packages/@vuepress/core/lib/app/Store.js

-19
This file was deleted.

packages/@vuepress/core/lib/app/app.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { siteData } from '@internal/siteData'
77
import appEnhancers from '@internal/app-enhancers'
88
import globalUIComponents from '@internal/global-ui'
99
import ClientComputedMixin from '@transform/ClientComputedMixin'
10-
import Store from './Store'
10+
import Store from './plugins/Store'
1111

1212
// built-in components
1313
import Content from './components/Content'
@@ -30,9 +30,8 @@ if (module.hot) {
3030

3131
Vue.config.productionTip = false
3232

33-
Vue.$store = new Store()
34-
3533
Vue.use(Router)
34+
Vue.use(Store, '$vuepress')
3635
// mixin for exposing $site and $page
3736
Vue.mixin(dataMixin(ClientComputedMixin, siteData))
3837
// component for rendering markdown content and setting title etc.
@@ -62,7 +61,7 @@ export function createApp (isServer) {
6261
if (saved) {
6362
return saved
6463
} else if (to.hash) {
65-
if (Vue.$store.get('disableScrollBehavior')) {
64+
if (Vue.$vuepress.$get('disableScrollBehavior')) {
6665
return false
6766
}
6867
return {

packages/@vuepress/core/lib/app/dataMixin.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import Vue from 'vue'
44

55
export default function dataMixin (I18n, siteData) {
66
prepare(siteData)
7-
Vue.$store.set('siteData', siteData)
7+
Vue.$vuepress.$set('siteData', siteData)
88

99
if (module.hot) {
1010
module.hot.accept(VUEPRESS_TEMP_PATH + '/internal/siteData.js', () => {
1111
prepare(siteData)
12-
Vue.$store.set('siteData', siteData)
12+
Vue.$vuepress.$set('siteData', siteData)
1313
})
1414
}
1515

16-
const I18nConstructor = I18n(Vue.$store.get('siteData'))
16+
const I18nConstructor = I18n(Vue.$vuepress.$get('siteData'))
1717
const i18n = new I18nConstructor()
1818
const descriptors = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(i18n))
1919
const computed = {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import Vue from 'vue'
2+
3+
class Store {
4+
constructor () {
5+
this.store = new Vue({
6+
data: {
7+
state: {}
8+
}
9+
})
10+
}
11+
12+
$get (key) {
13+
return this.store.state[key]
14+
}
15+
16+
$set (key, value) {
17+
Vue.set(this.store.state, key, value)
18+
}
19+
20+
$emit (...args) {
21+
this.store.$emit(...args)
22+
}
23+
24+
$on (...args) {
25+
this.store.$on(...args)
26+
}
27+
}
28+
29+
export default {
30+
install (Vue, options = '$store') {
31+
const store = new Store()
32+
Vue[options] = store
33+
Vue.prototype[options] = store
34+
}
35+
}

0 commit comments

Comments
 (0)