diff --git a/src/guide/component-dynamic-async.md b/src/guide/component-dynamic-async.md index 70f3f059bd..d66fa754f6 100644 --- a/src/guide/component-dynamic-async.md +++ b/src/guide/component-dynamic-async.md @@ -38,9 +38,11 @@ Check out more details on `` in the [API reference](../api/built-in- 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: ```js -const app = Vue.createApp({}) +const { createApp, defineAsyncComponent } = Vue -const AsyncComp = Vue.defineAsyncComponent( +const app = createApp({}) + +const AsyncComp = defineAsyncComponent( () => new Promise((resolve, reject) => { resolve({ diff --git a/src/guide/routing.md b/src/guide/routing.md index 288f5bef4d..dde5b00a3e 100644 --- a/src/guide/routing.md +++ b/src/guide/routing.md @@ -9,6 +9,8 @@ For most Single Page Applications, it's recommended to use the officially-suppor 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: ```js +const { createApp, h } = Vue + const NotFoundComponent = { template: '

Page not found

' } const HomeComponent = { template: '

Home page

' } const AboutComponent = { template: '

About page

' } @@ -30,11 +32,11 @@ const SimpleRouter = { }, render() { - return Vue.h(this.CurrentComponent) + return h(this.CurrentComponent) } } -Vue.createApp(SimpleRouter).mount('#app') +createApp(SimpleRouter).mount('#app') ``` 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). diff --git a/src/guide/state-management.md b/src/guide/state-management.md index 0525003cbc..366df48ca2 100644 --- a/src/guide/state-management.md +++ b/src/guide/state-management.md @@ -13,17 +13,19 @@ If you're coming from React, you may be wondering how vuex compares to [redux](h 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: ```js -const sourceOfTruth = Vue.reactive({ +const { createApp, reactive } = Vue + +const sourceOfTruth = reactive({ message: 'Hello' }) -const appA = Vue.createApp({ +const appA = createApp({ data() { return sourceOfTruth } }).mount('#app-a') -const appB = Vue.createApp({ +const appB = createApp({ data() { return sourceOfTruth } @@ -39,7 +41,7 @@ const appB = Vue.createApp({ 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. ```js -const appB = Vue.createApp({ +const appB = createApp({ data() { return sourceOfTruth }, @@ -55,7 +57,7 @@ To help solve this problem, we can adopt a **store pattern**: const store = { debug: true, - state: Vue.reactive({ + state: reactive({ message: 'Hello!' }), @@ -88,7 +90,7 @@ In addition, each instance/component can still own and manage its own private st ``` ```js -const appA = Vue.createApp({ +const appA = createApp({ data() { return { privateState: {}, @@ -100,7 +102,7 @@ const appA = Vue.createApp({ } }).mount('#app-a') -const appB = Vue.createApp({ +const appB = createApp({ data() { return { privateState: {},