Skip to content

Commit e5b34b2

Browse files
docs: swap more examples to destructuring for accessing the global Vue (#808)
1 parent 7745e70 commit e5b34b2

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/guide/component-dynamic-async.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ Check out more details on `<keep-alive>` in the [API reference](../api/built-in-
3838
In large applications, we may need to divide the app into smaller chunks and only load a component from the server when it's needed. To make that possible, Vue has a `defineAsyncComponent` method:
3939

4040
```js
41-
const app = Vue.createApp({})
41+
const { createApp, defineAsyncComponent } = Vue
4242

43-
const AsyncComp = Vue.defineAsyncComponent(
43+
const app = createApp({})
44+
45+
const AsyncComp = defineAsyncComponent(
4446
() =>
4547
new Promise((resolve, reject) => {
4648
resolve({

src/guide/routing.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ For most Single Page Applications, it's recommended to use the officially-suppor
99
If you only need very simple routing and do not wish to involve a full-featured router library, you can do so by dynamically rendering a page-level component like this:
1010

1111
```js
12+
const { createApp, h } = Vue
13+
1214
const NotFoundComponent = { template: '<p>Page not found</p>' }
1315
const HomeComponent = { template: '<p>Home page</p>' }
1416
const AboutComponent = { template: '<p>About page</p>' }
@@ -30,11 +32,11 @@ const SimpleRouter = {
3032
},
3133

3234
render() {
33-
return Vue.h(this.CurrentComponent)
35+
return h(this.CurrentComponent)
3436
}
3537
}
3638

37-
Vue.createApp(SimpleRouter).mount('#app')
39+
createApp(SimpleRouter).mount('#app')
3840
```
3941

4042
Combined with the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API/Working_with_the_History_API), you can build a very basic but fully-functional client-side router. To see that in practice, check out [this example app](https://github.com/phanan/vue-3.0-simple-routing-example).

src/guide/state-management.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ If you're coming from React, you may be wondering how vuex compares to [redux](h
1313
It is often overlooked that the source of truth in Vue applications is the reactive `data` object - a component instance only proxies access to it. Therefore, if you have a piece of state that should be shared by multiple instances, you can use a [reactive](/guide/reactivity-fundamentals.html#declaring-reactive-state) method to make an object reactive:
1414

1515
```js
16-
const sourceOfTruth = Vue.reactive({
16+
const { createApp, reactive } = Vue
17+
18+
const sourceOfTruth = reactive({
1719
message: 'Hello'
1820
})
1921

20-
const appA = Vue.createApp({
22+
const appA = createApp({
2123
data() {
2224
return sourceOfTruth
2325
}
2426
}).mount('#app-a')
2527

26-
const appB = Vue.createApp({
28+
const appB = createApp({
2729
data() {
2830
return sourceOfTruth
2931
}
@@ -39,7 +41,7 @@ const appB = Vue.createApp({
3941
Now whenever `sourceOfTruth` is mutated, both `appA` and `appB` will update their views automatically. We have a single source of truth now, but debugging would be a nightmare. Any piece of data could be changed by any part of our app at any time, without leaving a trace.
4042

4143
```js
42-
const appB = Vue.createApp({
44+
const appB = createApp({
4345
data() {
4446
return sourceOfTruth
4547
},
@@ -55,7 +57,7 @@ To help solve this problem, we can adopt a **store pattern**:
5557
const store = {
5658
debug: true,
5759

58-
state: Vue.reactive({
60+
state: reactive({
5961
message: 'Hello!'
6062
}),
6163

@@ -88,7 +90,7 @@ In addition, each instance/component can still own and manage its own private st
8890
```
8991

9092
```js
91-
const appA = Vue.createApp({
93+
const appA = createApp({
9294
data() {
9395
return {
9496
privateState: {},
@@ -100,7 +102,7 @@ const appA = Vue.createApp({
100102
}
101103
}).mount('#app-a')
102104

103-
const appB = Vue.createApp({
105+
const appB = createApp({
104106
data() {
105107
return {
106108
privateState: {},

0 commit comments

Comments
 (0)