Skip to content

Swap more examples to destructuring for accessing the global Vue #808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/guide/component-dynamic-async.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ Check out more details on `<keep-alive>` 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({
Expand Down
6 changes: 4 additions & 2 deletions src/guide/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<p>Page not found</p>' }
const HomeComponent = { template: '<p>Home page</p>' }
const AboutComponent = { template: '<p>About page</p>' }
Expand All @@ -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).
Expand Down
16 changes: 9 additions & 7 deletions src/guide/state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
},
Expand All @@ -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!'
}),

Expand Down Expand Up @@ -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: {},
Expand All @@ -100,7 +102,7 @@ const appA = Vue.createApp({
}
}).mount('#app-a')

const appB = Vue.createApp({
const appB = createApp({
data() {
return {
privateState: {},
Expand Down