Skip to content

Docs > Migration from Vue 2 の細かな差分 #359

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 3 commits into from
May 27, 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
20 changes: 12 additions & 8 deletions src/guide/migration/async-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ badges:
以前、非同期コンポーネントは Promise を返す関数としてコンポーネントを定義することで、このように簡単に作成されました:

```js
const asyncPage = () => import('./NextPage.vue')
const asyncModal = () => import('./Modal.vue')
```

または、オプション付きのさらに高度なコンポーネント構文として:

```js
const asyncPage = {
component: () => import('./NextPage.vue'),
const asyncModal = {
component: () => import('./Modal.vue'),
delay: 200,
timeout: 3000,
error: ErrorComponent,
Expand All @@ -45,25 +45,29 @@ import ErrorComponent from './components/ErrorComponent.vue'
import LoadingComponent from './components/LoadingComponent.vue'

// オプションなしの非同期コンポーネント
const asyncPage = defineAsyncComponent(() => import('./NextPage.vue'))
const asyncModal = defineAsyncComponent(() => import('./Modal.vue'))

// オプション付きの非同期コンポーネント
const asyncPageWithOptions = defineAsyncComponent({
loader: () => import('./NextPage.vue'),
const asyncModalWithOptions = defineAsyncComponent({
loader: () => import('./Modal.vue'),
delay: 200,
timeout: 3000,
errorComponent: ErrorComponent,
loadingComponent: LoadingComponent
})
```

::: tip NOTE
Vue Router は *遅延読み込み* と呼ばれるルートコンポーネントを非同期に読み込む似たような仕組みをサポートしています。似てはいますが、この機能は Vue の非同期コンポーネントのサポートとは異なります。 Vue Router でルートコンポーネントを構成するときは、 `defineAsyncComponent` を **使用しない** 必要があります。これについては、 Vue Router のドキュメントの [ルートの遅延読み込み](https://next.router.vuejs.org/guide/advanced/lazy-loading.html) で詳しく説明されています。
:::

2.x からなされたもう一つの変更は、直接コンポーネント定義を提供できないことを正確に伝えるために `component` オプションの名前が `loader` に替わったことです。

```js{4}
import { defineAsyncComponent } from 'vue'

const asyncPageWithOptions = defineAsyncComponent({
loader: () => import('./NextPage.vue'),
const asyncModalWithOptions = defineAsyncComponent({
loader: () => import('./Modal.vue'),
delay: 200,
timeout: 3000,
errorComponent: ErrorComponent,
Expand Down
4 changes: 2 additions & 2 deletions src/guide/migration/custom-directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ app.directive('highlight', {

Vue 2 では、コンポーネントインスタンスは `vnode` 引数を使ってアクセスする必要がありました。

```javascript
```js
bind(el, binding, vnode) {
const vm = vnode.context
}
```

Vue 3 では、インスタンスは `binding` の一部になりました。

```javascript
```js
mounted(el, binding, vnode) {
const vm = binding.instance
}
Expand Down
2 changes: 1 addition & 1 deletion src/guide/migration/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ badges:

その代わり、 [globalProperties](../../api/application-config.html#globalproperties) によって、すべてのコンポーネントがグローバルフィルタを利用できるようにすることができます:

```javascript
```js
// main.js
const app = createApp(App)

Expand Down
2 changes: 1 addition & 1 deletion src/guide/migration/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Vue 3 で注目すべきいくつかの新機能の次のとおりです。
- [Fragments](/guide/migration/fragments.html)
- [Emits Component Option](/guide/component-custom-events.html)
- カスタムレンダラを作るための [`@vue/runtime-core` の `createRenderer` API](https://github.com/vuejs/vue-next/tree/master/packages/runtime-core)
- [SFC での Composition API の Syntax Sugar (`<script setup>`)](https://github.com/vuejs/rfcs/blob/sfc-improvements/active-rfcs/0000-sfc-script-setup.md) <Badge text="experimental" type="warning" />
- [SFC での Composition API の Syntax Sugar (`<script setup>`)](https://github.com/vuejs/rfcs/blob/script-setup-2/active-rfcs/0000-script-setup.md) <Badge text="experimental" type="warning" />
- [SFC でのステートドリブンな CSS Variables (`<style>` の `v-bind`)](https://github.com/vuejs/rfcs/blob/style-vars-2/active-rfcs/0000-sfc-style-variables.md) <Badge text="experimental" type="warning" />
- [SFC での `<style scoped>` は、グローバルルールまたはスロットされたコンテンツのみを対象とするルールを含めることができるようになった](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0023-scoped-styles-changes.md)
- [Suspense](/guide/migration/suspense.html) <Badge text="experimental" type="warning" />
Expand Down
4 changes: 2 additions & 2 deletions src/guide/migration/listeners-removed.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ badges:

`$listeners` オブジェクトは Vue 3 で削除されました。イベントリスナは `$attrs` の一部になりました。

```javascript
```js
{
text: 'this is an attribute',
onClose: () => console.log('close Event triggered')
Expand Down Expand Up @@ -54,7 +54,7 @@ export default {

もしこのコンポーネントが `id` 属性と `v-on:close` リスナを受け取った場合、 `$attrs` オブジェクトは次のようになります:

```javascript
```js
{
id: 'my-input',
onClose: () => console.log('close Event triggered')
Expand Down