diff --git a/.vitepress/locales/ja.js b/.vitepress/locales/ja.js index 0372d60..f20f678 100644 --- a/.vitepress/locales/ja.js +++ b/.vitepress/locales/ja.js @@ -28,14 +28,14 @@ export default { ] }, { - text: 'Global API', + text: 'グローバル API', items: [ { - text: 'Global API Application Instance', + text: 'グローバル API アプリケーションインスタンス', link: '/ja/breaking-changes/global-api' }, { - text: 'Global API Treeshaking', + text: 'グローバル API ツリーシェイキング', link: '/ja/breaking-changes/global-api-treeshaking' } ] diff --git a/.vitepress/theme/MigrationBadges.vue b/.vitepress/theme/MigrationBadges.vue index 46b1170..81ae1f5 100644 --- a/.vitepress/theme/MigrationBadges.vue +++ b/.vitepress/theme/MigrationBadges.vue @@ -13,6 +13,12 @@ const localeBadges = { breaking: '非兼容', removed: '移除', updated: '更新' + }, + 'ja-JP': { + new: '新機能', + breaking: '破壊的変更', + removed: '削除', + updated: '更新' } } diff --git a/src/ja/breaking-changes/global-api-treeshaking.md b/src/ja/breaking-changes/global-api-treeshaking.md index f4c1184..9a9079d 100644 --- a/src/ja/breaking-changes/global-api-treeshaking.md +++ b/src/ja/breaking-changes/global-api-treeshaking.md @@ -3,21 +3,21 @@ badges: - breaking --- -# Global API Treeshaking +# グローバル API ツリーシェイキング -## 2.x Syntax +## 2.x の構文 -If you’ve ever had to manually manipulate DOM in Vue, you might have come across this pattern: +Vue で DOM を手動で操作したことがある人は、次のパターンに出くわしたことがあるかもしれません: ```js import Vue from 'vue' Vue.nextTick(() => { - // something DOM-related + // DOM 関連の何か }) ``` -Or, if you’ve been unit-testing an application involving async components, chances are you’ve written something like this: +あるいは、非同期コンポーネントを含むアプリケーションをユニットテストしている場合、次のようなことを書いたことがあるのではないでしょうか: ```js import { shallowMount } from '@vue/test-utils' @@ -26,33 +26,33 @@ import { MyComponent } from './MyComponent.vue' test('an async feature', async () => { const wrapper = shallowMount(MyComponent) - // execute some DOM-related tasks + // DOM に関連するいくつかのタスクを実行 await wrapper.vm.$nextTick() - // run your assertions + // アサーション実行 }) ``` -`Vue.nextTick()` is a global API exposed directly on a single Vue object – in fact, the instance method `$nextTick()` is just a handy wrapper around `Vue.nextTick()` with the callback’s `this` context automatically bound to the current instance for convenience. +`Vue.nextTick()` は、単一の Vue オブジェクト上で直接公開されるグローバル API です - 実際のところ、インスタンスメソッド `$nextTick()` は `Vue.nextTick()` の便利なラッパーに過ぎず、コールバックの `this` コンテキストは便宜上、現在のインスタンスに自動的に結合されます。 -But what if you’ve never had to deal with manual DOM manipulation, nor are you using or testing async components in your app? Or, what if, for whatever reason, you prefer to use the good old `window.setTimeout()` instead? In such a case, the code for `nextTick()` will become dead code – that is, code that’s written but never used. And dead code is hardly a good thing, especially in our client-side context where every kilobyte matters. +しかし、手動で DOM を操作する必要がなく、アプリで非同期コンポーネントを使用したりテストしたりすることもない場合はどうでしょうか? あるいは、何らかの理由で、代わりに古き良き `window.setTimeout()` を使いたい場合はどうでしょうか? このような場合、`nextTick()` のコードはデッドコード、つまり、書かれているが使われないコードになってしまいます。特に、1 キロバイト単位が重要なクライアントサイドの文脈では、デッドコードは良いことではありません。 -Module bundlers like webpack and Rollup (which Vite is based upon) support [tree-shaking](https://webpack.js.org/guides/tree-shaking/), which is a fancy term for “dead code elimination.” Unfortunately, due to how the code is written in previous Vue versions, global APIs like `Vue.nextTick()` are not tree-shakeable and will be included in the final bundle regardless of where they are actually used or not. +webpack や(Vite のベースとなっている)Rollup のようなモジュールバンドラーは、[ツリーシェイキング](https://webpack.js.org/guides/tree-shaking/)をサポートしています。これは「デッドコードの排除」を意味する装飾的な用語です。残念ながら以前の Vue バージョンではコードの記述方法が原因で、`Vue.nextTick()` のようなグローバル API はツリーシェイクされず、実際に使われる場所や使わない場所に関係なく最終的にバンドルに含まれます。 -## 3.x Syntax +## 3.x の構文 -In Vue 3, the global and internal APIs have been restructured with tree-shaking support in mind. As a result, the global APIs can now only be accessed as named exports for the ES Modules build. For example, our previous snippets should now look like this: +Vue 3 では、ツリーシェイキングのサポートを念頭に置いて、グローバル API と内部 API が再構築されました。その結果、グローバル API は、ES モジュールビルドの名前付きエクスポートとしてのみアクセスできるようになりました。例えば、上記のスニペットは次のようになります: ```js import { nextTick } from 'vue' nextTick(() => { - // something DOM-related + // DOM 関連の何か }) ``` -and +さらに ```js import { shallowMount } from '@vue/test-utils' @@ -62,32 +62,32 @@ import { nextTick } from 'vue' test('an async feature', async () => { const wrapper = shallowMount(MyComponent) - // execute some DOM-related tasks + // DOM に関連するいくつかのタスクを実行 await nextTick() - // run your assertions + // アサーション実行 }) ``` -Calling `Vue.nextTick()` directly will now result in the infamous `undefined is not a function` error. +`Vue.nextTick()` を直接呼び出すと、悪名高い `undefined is not a function` エラーが発生するようになりました。 -With this change, provided the module bundler supports tree-shaking, global APIs that are not used in a Vue application will be eliminated from the final bundle, resulting in an optimal file size. +この変更により、モジュールバンドラーがツリーシェイキングをサポートしている場合、Vue アプリケーションで使用されないグローバル API は最終的なバンドルから排除され、最適なファイルサイズになります。 -## Affected APIs +## 影響を受ける API -These global APIs in Vue 2.x are affected by this change: +以下の Vue 2.x のグローバル API は、この変更の影響を受けます: - `Vue.nextTick` -- `Vue.observable` (replaced by `Vue.reactive`) +- `Vue.observable`(`Vue.reactive` に置き換え) - `Vue.version` -- `Vue.compile` (only in full builds) -- `Vue.set` (only in compat builds) -- `Vue.delete` (only in compat builds) +- `Vue.compile`(フルビルドのみ) +- `Vue.set`(互換ビルドのみ) +- `Vue.delete`(互換ビルドのみ) -## Internal Helpers +## 内部ヘルパー -In addition to public APIs, many of the internal components/helpers are now exported as named exports as well. This allows the compiler to output code that only imports features when they are used. For example the following template: +パブリック API に加え、内部コンポーネントやヘルパーの多くも名前付きエクスポートとして公開されるようになりました。これにより、コンパイラーは、機能が使用されるときだけインポートするコードを出力できます。例えば次のテンプレートは: ```html @@ -95,7 +95,7 @@ In addition to public APIs, many of the internal components/helpers are now expo ``` -is compiled into something similar to the following: +以下のようなものにコンパイルされます: ```js import { h, Transition, withDirectives, vShow } from 'vue' @@ -105,17 +105,17 @@ export function render() { } ``` -This essentially means the `Transition` component only gets imported when the application actually makes use of it. In other words, if the application doesn’t have any `` component, the code supporting this feature will not be present in the final bundle. +つまり、`Transition` コンポーネントは、アプリケーションが実際に使用するときにのみインポートされます。言い換えれば、アプリケーションが `` コンポーネントを持たない場合、この機能をサポートするコードは最終的なバンドルには含まれません。 -With global tree-shaking, the users only “pay” for the features they actually use. Even better, knowing that optional features won't increase the bundle size for applications not using them, framework size has become much less a concern for additional core features in the future, if at all. +グローバルのツリーシェイキングでは、ユーザーは実際に使用する機能に対してのみ「支払う」ことになります。さらに良いことに、オプション機能を使用しないアプリケーションではバンドルサイズが大きくならないことが分かっているため、将来的にコア機能を追加する場合でも、フレームワークのサイズについて懸念することは少なくなっています。 -::: warning Important -The above only applies to the [ES Modules builds](https://github.com/vuejs/core/tree/master/packages/vue#which-dist-file-to-use) for use with tree-shaking capable bundlers - the UMD build still includes all features and exposes everything on the Vue global variable (and the compiler will produce appropriate output to use APIs off the global instead of importing). +::: warning 重要 +上記は、ツリーシェイキング可能なバンドラーで使用するための [ES モジュールビルド](https://github.com/vuejs/core/tree/master/packages/vue#which-dist-file-to-use)にのみ適用されます。UMD ビルドは依然としてすべての機能を含み、Vue グローバル変数ですべてを公開します(そしてコンパイラーは、インポートする代わりにグローバルから API を使用するように適切な出力を生成します)。 ::: -## Usage in Plugins +## プラグインでの使用 -If your plugin relies on an affected Vue 2.x global API, for instance: +あなたのプラグインが、影響を受ける Vue 2.x のグローバル API に依存している場合、例えば: ```js const plugin = { @@ -127,7 +127,7 @@ const plugin = { } ``` -In Vue 3, you’ll have to import it explicitly: +Vue 3 では、明示的にインポートする必要があります: ```js import { nextTick } from 'vue' @@ -141,7 +141,7 @@ const plugin = { } ``` -If you use a module bundle like webpack, this may cause Vue’s source code to be bundled into the plugin, and more often than not that’s not what you'd expect. A common practice to prevent this from happening is to configure the module bundler to exclude Vue from the final bundle. In webpack's case, you can use the [`externals`](https://webpack.js.org/configuration/externals/) configuration option: +webpack のようなモジュールバンドルを使っている場合、Vue のソースコードがプラグインにバンドルされてしまうことがあり、それはほとんどが期待するものではないです。これを防ぐための一般的な方法は、最終的なバンドルから Vue を除外するようにモジュールバンドラーを設定することです。webpack の場合、[`externals`](https://webpack.js.org/configuration/externals/) という設定オプションを使用します: ```js // webpack.config.js @@ -153,9 +153,9 @@ module.exports = { } ``` -This will tell webpack to treat the Vue module as an external library and not bundle it. +これは webpack に、Vue モジュールを外部ライブラリーとして扱い、バンドルしないように指示します。 -If your module bundler of choice happens to be [Rollup](https://rollupjs.org/), you basically get the same effect for free, as by default Rollup will treat absolute module IDs (`'vue'` in our case) as external dependencies and not include them in the final bundle. During bundling though, it might emit a [“Treating vue as external dependency”](https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency) warning, which can be suppressed with the `external` option: +モジュールバンドラーに [Rollup](https://rollupjs.org/) を選択した場合、基本的には何もせずに同じ効果を得られます。デフォルトでは Rollup は絶対モジュール ID(この例では `'vue'`)を外部依存関係として扱い、最終バンドルに含めないからです。しかし、バンドル中に ["Treating vue as external dependency"](https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency) という警告が出ることがありますが、これは `external` オプションで抑制できます: ```js // rollup.config.js diff --git a/src/ja/breaking-changes/global-api.md b/src/ja/breaking-changes/global-api.md index 043f3ee..e141288 100644 --- a/src/ja/breaking-changes/global-api.md +++ b/src/ja/breaking-changes/global-api.md @@ -3,9 +3,9 @@ badges: - breaking --- -# Global API Application Instance +# グローバル API アプリケーションインスタンス -Vue 2.x has a number of global APIs and configurations that globally mutate Vue’s behavior. For instance, to register a global component, you would use the `Vue.component` API like this: +Vue 2.x には、Vue の動作をグローバルに変更するグローバル API や設定が多数用意されています。例えばグローバルコンポーネントを登録するには、次のように `Vue.component` API を使用します: ```js Vue.component('button-counter', { @@ -16,7 +16,7 @@ Vue.component('button-counter', { }) ``` -Similarly, this is how a global directive is declared: +同様に、グローバルディレクティブもこのように宣言します: ```js Vue.directive('focus', { @@ -24,27 +24,27 @@ Vue.directive('focus', { }) ``` -While this approach is convenient, it leads to a couple of problems. Technically, Vue 2 doesn't have a concept of an "app". What we define as an app is simply a root Vue instance created via `new Vue()`. Every root instance created from the same Vue constructor **shares the same global configuration**. As a result: +この方法は便利ですが、いくつかの問題を引き起こします。技術的には、Vue 2 には「アプリ」という概念がありません。私たちがアプリと定義しているのは、単に `new Vue()` によって作成されたルート Vue インスタンスです。同じ Vue コンストラクターから作成されたすべてのルートインスタンスは、**同じグローバル設定を共有します**。その結果、以下のようになります: -- Global configuration makes it easy to accidentally pollute other test cases during testing. Users need to carefully store original global configuration and restore it after each test (e.g. resetting `Vue.config.errorHandler`). Some APIs like `Vue.use` and `Vue.mixin` don't even have a way to revert their effects. This makes tests involving plugins particularly tricky. In fact, vue-test-utils has to implement a special API `createLocalVue` to deal with this: +- グローバル設定は、テスト中に誤って他のテストケースを汚染しやすくなります。ユーザーは慎重に元のグローバル設定を保存し、テストのたびにそれを復元(例えば `Vue.config.errorHandler` をリセット)する必要があります。`Vue.use` や `Vue.mixin` のような一部の API は、その作用を元に戻す方法さえ持っていません。このため、プラグインを含むテストは特にやっかいです。実際、vue-test-utils はこれに対処するため、特別な API の `createLocalVue` を実行する必要があります: ```js import { createLocalVue, mount } from '@vue/test-utils' - // create an extended `Vue` constructor + // 拡張された `Vue` コンストラクターを作成 const localVue = createLocalVue() - // install a plugin “globally” on the “local” Vue constructor + // 「ローカル」の Vue コンストラクターへ、プラグインを「グローバル」にインストール localVue.use(MyPlugin) - // pass the `localVue` to the mount options + // mount のオプションに `localVue` を渡す mount(Component, { localVue }) ``` -- Global configuration makes it difficult to share the same copy of Vue between multiple "apps" on the same page, but with different global configurations. +- グローバル設定によって、同じページ上にありながらグローバル設定が異なる複数の「アプリ」間で、同じ Vue のコピーを共有することが難しくなります。 ```js - // this affects both root instances + // これは両方のルートインスタンスに影響する Vue.mixin({ /* ... */ }) @@ -53,11 +53,11 @@ While this approach is convenient, it leads to a couple of problems. Technically const app2 = new Vue({ el: '#app-2' }) ``` -To avoid these problems, in Vue 3 we introduce… +このような問題を回避するために、Vue 3 では… -## A New Global API: `createApp` {#a-new-global-api-createapp} +## 新しいグローバル API: `createApp` {#a-new-global-api-createapp} -Calling `createApp` returns an _app instance_, a new concept in Vue 3. +`createApp` を呼び出すと、Vue 3 の新しい概念である**app インスタンス**が返されます。 ```js import { createApp } from 'vue' @@ -65,7 +65,7 @@ import { createApp } from 'vue' const app = createApp({}) ``` -If you're using a CDN build of Vue then `createApp` is exposed via the global `Vue` object: +Vue の CDN ビルドを使用している場合、`createApp` はグローバルな `Vue` オブジェクトを通じて公開されます: ```js const { createApp } = Vue @@ -73,82 +73,82 @@ const { createApp } = Vue const app = createApp({}) ``` -An app instance exposes a subset of the Vue 2 global APIs. The rule of thumb is _any APIs that globally mutate Vue's behavior are now moved to the app instance_. Here is a table of the Vue 2 global APIs and their corresponding instance APIs: +アプリインスタンスは、Vue 2 のグローバル API のサブセットを公開します。基本的に、Vue の動作をグローバルに変更する API は、すべてアプリインスタンスに移動されました。以下は、Vue 2 のグローバル API とそれに対応するインスタンス API の表です: -| 2.x Global API | 3.x Instance API (`app`) | +| 2.x のグローバル API | 3.x のインスタンス API (`app`) | | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------- | | Vue.config | app.config | -| Vue.config.productionTip | _removed_ ([see below](#config-productiontip-removed)) | -| Vue.config.ignoredElements | app.config.compilerOptions.isCustomElement ([see below](#config-ignoredelements-is-now-config-compileroptions-iscustomelement)) | +| Vue.config.productionTip | 削除されました([下記参照](#config-productiontip-removed)) | +| Vue.config.ignoredElements | app.config.compilerOptions.isCustomElement([下記参照](#config-ignoredelements-is-now-config-compileroptions-iscustomelement)) | | Vue.component | app.component | | Vue.directive | app.directive | | Vue.mixin | app.mixin | -| Vue.use | app.use ([see below](#a-note-for-plugin-authors)) | -| Vue.prototype | app.config.globalProperties ([see below](#vue-prototype-replaced-by-config-globalproperties)) | -| Vue.extend | _removed_ ([see below](#vue-extend-removed)) | +| Vue.use | app.use([下記参照](#a-note-for-plugin-authors)) | +| Vue.prototype | app.config.globalProperties([下記参照](#vue-prototype-replaced-by-config-globalproperties)) | +| Vue.extend | 削除されました([下記参照](#vue-extend-removed)) | -All other global APIs that do not globally mutate behavior are now named exports, as documented in [Global API Treeshaking](./global-api-treeshaking.html). +[グローバル API ツリーシェイキング](./global-api-treeshaking.html)に記載されているように、動作をグローバルに変更しない他のすべてのグローバル API は named exports されるようになりました。 -### `config.productionTip` Removed {#config-productiontip-removed} +### `config.productionTip` は削除されました {#config-productiontip-removed} -In Vue 3.x, the "use production build" tip will only show up when using the "dev + full build" (the build that includes the runtime compiler and has warnings). +Vue 3.x では、「開発 + フルビルド」(ランタイムコンパイラを含み、警告があるビルド)を使用する場合にのみ、「use production build」というヒントが表示されます。 -For ES modules builds, since they are used with bundlers, and in most cases a CLI or boilerplate would have configured the production env properly, this tip will no longer show up. +ES モジュールのビルドの場合、バンドラーと共に使用されて、CLI やボイラープレートによってプロダクション環境を適切に設定できる場合がほとんどなので、このヒントは表示されなくなりました。 -[Migration build flag: `CONFIG_PRODUCTION_TIP`](../migration-build.html#compat-configuration) +[移行ビルドのフラグ: `CONFIG_PRODUCTION_TIP`](../migration-build.html#compat-configuration) -### `config.ignoredElements` Is Now `config.compilerOptions.isCustomElement` {#config-ignoredelements-is-now-config-compileroptions-iscustomelement} +### `config.ignoredElements` は `config.compilerOptions.isCustomElement` になりました {#config-ignoredelements-is-now-config-compileroptions-iscustomelement} -This config option was introduced with the intention to support native custom elements, so the renaming better conveys what it does. The new option also expects a function which provides more flexibility than the old string / RegExp approach: +この設定オプションは、ネイティブのカスタム要素をサポートする目的で導入されたもので、名称を変更することで、その役割をより明確に伝えることができます。新しいオプションは、以前の文字列や正規表現のアプローチよりも柔軟性を提供する関数も受け付けます: ```js -// before +// 変更前 Vue.config.ignoredElements = ['my-el', /^ion-/] -// after +// 変更後 const app = createApp({}) app.config.compilerOptions.isCustomElement = (tag) => tag.startsWith('ion-') ``` -::: tip Important +::: tip 重要 -In Vue 3, the check of whether an element is a component or not has been moved to the template compilation phase, therefore this config option is only respected when using the runtime compiler. If you are using the runtime-only build, `isCustomElement` must be passed to `@vue/compiler-dom` in the build setup instead - for example, via the [`compilerOptions` option in vue-loader](https://vue-loader.vuejs.org/options.html#compileroptions). +Vue 3 では、要素がコンポーネントかどうかのチェックはテンプレートのコンパイルフェーズに移されたため、この設定オプションはランタイムコンパイラーを使用する場合にのみ考慮されます。ランタイムのみのビルドを使用する場合、`isCustomElement` はビルドの設定で `@vue/compiler-dom` に渡す必要があります。例えば、vue-loader の [`compilerOptions` オプション](https://vue-loader.vuejs.org/options.html#compileroptions)で渡します。 -- If `config.compilerOptions.isCustomElement` is assigned to when using a runtime-only build, a warning will be emitted instructing the user to pass the option in the build setup instead; -- This will be a new top-level option in the Vue CLI config. +- ランタイムのみのビルドを使用しているときに `config.compilerOptions.isCustomElement` が割り当てられた場合、代わりにビルド設定でオプションを渡すように指示する警告が表示されます。 +- これは、Vue CLI 設定の新しいトップレベルオプションとなります。 ::: -[Migration build flag: `CONFIG_IGNORED_ELEMENTS`](../migration-build.html#compat-configuration) +[移行ビルドのフラグ: `CONFIG_IGNORED_ELEMENTS`](../migration-build.html#compat-configuration) -### `Vue.prototype` Replaced by `config.globalProperties` {#vue-prototype-replaced-by-config-globalproperties} +### `Vue.prototype` は `config.globalProperties` に置き換わりました {#vue-prototype-replaced-by-config-globalproperties} -In Vue 2, `Vue.prototype` was commonly used to add properties that would be accessible in all components. +Vue 2 では一般的に、すべてのコンポーネントでアクセス可能なプロパティを追加するために `Vue.prototype` が使用されました。 -The equivalent in Vue 3 is [`config.globalProperties`](https://ja.vuejs.org/api/application.html#app-config-globalproperties). These properties will be copied across as part of instantiating a component within the application: +Vue 3 でこれに相当するのは [`config.globalProperties`](https://ja.vuejs.org/api/application.html#app-config-globalproperties) です。これらのプロパティは、アプリケーション内でコンポーネントをインスタンス化する際に、その一部としてコピーされることになります: ```js -// before - Vue 2 +// 変更前 - Vue 2 Vue.prototype.$http = () => {} ``` ```js -// after - Vue 3 +// 変更後 - Vue 3 const app = createApp({}) app.config.globalProperties.$http = () => {} ``` -Using `provide` (discussed [below](#provide-inject)) should also be considered as an alternative to `globalProperties`. +また、`globalProperties` の代替として、`provide`([後述](#provide-inject))の使用も検討する必要があります。 -[Migration build flag: `GLOBAL_PROTOTYPE`](../migration-build.html#compat-configuration) +[移行ビルドのフラグ: `GLOBAL_PROTOTYPE`](../migration-build.html#compat-configuration) -### `Vue.extend` Removed {#vue-extend-removed} +### `Vue.extend` は削除されました {#vue-extend-removed} -In Vue 2.x, `Vue.extend` was used to create a "subclass" of the base Vue constructor with the argument that should be an object containing component options. In Vue 3.x, we don't have the concept of component constructors anymore. Mounting a component should always use the `createApp` global API: +Vue 2.x では、`Vue.extend` を使用して、コンポーネントオプションを含むオブジェクトを引数とするベース Vue コンストラクターの「サブクラス」を作成しました。Vue 3.x では、コンポーネントコンストラクターという概念はなくなりました。コンポーネントをマウントするには、常にグローバル API の `createApp` を使用する必要があります: ```js -// before - Vue 2 +// 変更前 - Vue 2 -// create constructor +// コンストラクター作成 const Profile = Vue.extend({ template: '

{{firstName}} {{lastName}} aka {{alias}}

', data() { @@ -159,12 +159,12 @@ const Profile = Vue.extend({ } } }) -// create an instance of Profile and mount it on an element +// Profile のインスタンスを生成し、要素にマウント new Profile().$mount('#mount-point') ``` ```js -// after - Vue 3 +// 変更後 - Vue 3 const Profile = { template: '

{{firstName}} {{lastName}} aka {{alias}}

', data() { @@ -179,21 +179,21 @@ const Profile = { Vue.createApp(Profile).mount('#mount-point') ``` -#### Type Inference +#### 型推論 -In Vue 2, `Vue.extend` was also used for providing TypeScript type inference for the component options. In Vue 3, the `defineComponent` global API can be used in place of `Vue.extend` for the same purpose. +Vue 2 では、`Vue.extend` はコンポーネントオプションの TypeScript 型推論を提供するためにも使用されました。Vue 3 では、同じ目的で `Vue.extend` の代わりにグローバル API の `defineComponent` を使用できます。 -Note that although the return type of `defineComponent` is a constructor-like type, it is only used for TSX inference. At runtime `defineComponent` is largely a noop and will return the options object as-is. +`defineComponent` の戻り値はコンストラクターのような型ですが、TSX 推論にのみ使用されることに注意してください。実行時には、`defineComponent` はほとんど何もせず、オプションオブジェクトをそのまま返します。 -#### Component Inheritance +#### コンポーネントの継承 -In Vue 3, we strongly recommend favoring composition via [Composition API](https://ja.vuejs.org/guide/reusability/composables.html) over inheritance and mixins. If for some reason you still need component inheritance, you can use the [`extends` option](https://ja.vuejs.org/api/options-composition.html#extends) instead of `Vue.extend`. +Vue 3 では、継承やミックスインよりも、[Composition API](https://ja.vuejs.org/guide/reusability/composables.html) によるコンポジションを強く推奨しています。何らかの理由でコンポーネントの継承が必要な場合は、`Vue.extend` の代わりに [`extends` オプション](https://ja.vuejs.org/api/options-composition.html#extends)を使用できます。 -[Migration build flag: `GLOBAL_EXTEND`](../migration-build.html#compat-configuration) +[移行ビルドのフラグ: `GLOBAL_EXTEND`](../migration-build.html#compat-configuration) -### A Note for Plugin Authors +### プラグイン作者への注意事項 -It is a common practice for plugin authors to install the plugins automatically in their UMD builds using `Vue.use`. For instance, this is how the official `vue-router` plugin installs itself in a browser environment: +プラグイン作者は、UMD ビルドの際に `Vue.use` を使ってプラグインを自動的にインストールするのが一般的なやり方です。例えば、公式の `vue-router` プラグインは、以下のようにブラウザー環境にインストールされます: ```js var inBrowser = typeof window !== 'undefined' @@ -203,16 +203,16 @@ if (inBrowser && window.Vue) { } ``` -As the `use` global API is no longer available in Vue 3, this method will cease to work and calling `Vue.use()` will now trigger a warning. Instead, the end-user will now have to explicitly specify using the plugin on the app instance: +Vue 3 ではグローバル API である `use` が利用できなくなったため、このやり方は機能しなくなり、`Vue.use()` を呼び出すと警告が表示されるようになりました。代わりに、エンドユーザーはアプリのインスタンスでプラグインの使用を明示的に指定する必要があります: ```js const app = createApp(MyApp) app.use(VueRouter) ``` -## Mounting App Instance {#mounting-app-instance} +## アプリインスタンスのマウント {#mounting-app-instance} -After being initialized with `createApp(/* options */)`, the app instance `app` can be used to mount a root component instance with `app.mount(domTarget)`: +`createApp(/* オプション */)` で初期化した後、アプリのインスタンス `app` を使って `app.mount(domTarget)` でルートコンポーネントのインスタンスをマウントできます: ```js import { createApp } from 'vue' @@ -222,7 +222,7 @@ const app = createApp(MyApp) app.mount('#app') ``` -With all these changes, the component and directive we have at the beginning of the guide will be rewritten into something like this: +これらの変更により、このガイドの冒頭にあるコンポーネントとディレクティブは、次のようなものに書き直されます: ```js const app = createApp(MyApp) @@ -238,23 +238,23 @@ app.directive('focus', { mounted: (el) => el.focus() }) -// now every application instance mounted with app.mount(), along with its -// component tree, will have the same “button-counter” component -// and “focus” directive without polluting the global environment +// これで、app.mount() でマウントされたすべてのアプリケーションインスタンスと +// そのコンポーネントツリーは、グローバル環境を汚染することなく、 +// 同じ button-counter コンポーネントと focus ディレクティブを持つことになります app.mount('#app') ``` -[Migration build flag: `GLOBAL_MOUNT`](../migration-build.html#compat-configuration) +[移行ビルドのフラグ: `GLOBAL_MOUNT`](../migration-build.html#compat-configuration) ## Provide / Inject -Similar to using the `provide` option in a 2.x root instance, a Vue 3 app instance can also provide dependencies that can be injected by any component inside the app: +2.x のルートインスタンスで `provide` オプションを使用するのと同様に、Vue 3 アプリインスタンスは、アプリ内の任意のコンポーネントによって注入される依存関係を提供できます: ```js -// in the entry +// エントリー内 app.provide('guide', 'Vue 3 Guide') -// in a child component +// 子コンポーネント内 export default { inject: { book: { @@ -265,11 +265,11 @@ export default { } ``` -Using `provide` is especially useful when writing a plugin, as an alternative to `globalProperties`. +`provide` の使用は `globalProperties` の代わりとして、特にプラグインを作成する際に便利です。 -## Share Configurations Among Apps +## アプリ間で設定を共有する -One way to share configurations e.g. components or directives among apps is to create a factory function, like this: +コンポーネントやディレクティブなどの設定をアプリ間で共有する方法のひとつに、次のようなファクトリー関数を作成する方法があります: ```js import { createApp } from 'vue' @@ -287,4 +287,4 @@ createMyApp(Foo).mount('#foo') createMyApp(Bar).mount('#bar') ``` -Now the `focus` directive will be available in both `Foo` and `Bar` instances and their descendants. +これで `focus` ディレクティブは `Foo` と `Bar` の両方のインスタンスとその子孫で利用できるようになりました。 diff --git a/src/ja/new/fragments.md b/src/ja/new/fragments.md index 2254ac2..728328a 100644 --- a/src/ja/new/fragments.md +++ b/src/ja/new/fragments.md @@ -3,15 +3,15 @@ badges: - new --- -# Fragments +# フラグメント -## Overview {#overview} +## 概要 {#overview} -In Vue 3, components now have official support for multi-root node components, i.e., fragments! +Vue 3 では、マルチルートノードのコンポーネント、つまりフラグメントを公式にサポートするようになりました! -## 2.x Syntax +## 2.x の構文 -In 2.x, multi-root components were not supported and would emit a warning when a user accidentally created one. As a result, many components are wrapped in a single `
` in order to fix this error. +2.x では、マルチルートコンポーネントはサポートされておらず、ユーザーが誤って作成すると警告が表示されました。その結果、このエラーを解決するために、多くのコンポーネントが 1 つの `
` でラップされていました。 ```html @@ -24,9 +24,9 @@ In 2.x, multi-root components were not supported and would emit a warning when a ``` -## 3.x Syntax +## 3.x の構文 -In 3.x, components now can have multiple root nodes! However, this does require developers to explicitly define where attributes should be distributed. +3.x では、コンポーネントは複数のルートノードを持つことができるようになりました! ただしこの場合、開発者は属性を配布する場所を明示的に定義する必要があります。 ```html @@ -37,4 +37,4 @@ In 3.x, components now can have multiple root nodes! However, this does require ``` -For more information on how attribute inheritance works, see [Fallthrough Attributes](https://ja.vuejs.org/guide/components/attrs.html#fallthrough-attributes). +属性継承の仕組みについては、[フォールスルー属性](https://ja.vuejs.org/guide/components/attrs.html#fallthrough-attributes)を参照してください。