|
1 |
| -# Migration ways |
| 1 | +# Migration from Vue 2 |
2 | 2 |
|
3 | 3 | ## `vue-i18n-bridge`
|
4 | 4 |
|
@@ -230,84 +230,3 @@ About how to usage, See the [here](https://github.com/intlify/vue-i18n-composabl
|
230 | 230 | :::warning NOTICE
|
231 | 231 | `vue-i18n-composable` allows the main API of Vue I18n v8.x to work with the Composition API. All of Composition API provided in Vue I18n v9 are not available.
|
232 | 232 | :::
|
233 |
| - |
234 |
| -## Migration to Composition API from Legacy API |
235 |
| - |
236 |
| -### Summary |
237 |
| - |
238 |
| -Vue I18n supports both styles which are Legacy API mode and Composiyion API mode. Legacy API mode is Options API style, and Composition API mode support Vue Composition API that is able to compose with function. |
239 |
| - |
240 |
| -Legacy API mode is almost compatible with legacy Vue I18n v8.x, making it relatively easy to migrate Vue applications to Vue 3. Vue 3 supports the Options API style, so existing Vue 2 applications will be cases where applications will be migrated to Vue 3. |
241 |
| - |
242 |
| -Vue 3 allows you to make Vue applications using a mix of the Options API style and Composition API style, but Vue I18n has not allowed for a mix of these API styles since the v9 initial release, so you can use either one or the other API style only. |
243 |
| - |
244 |
| -Developing a Vue application with a mix of Options API styles and Compostion API styles is not a desirable software development project from a maintenance standpoint. This is because the cost of maintaining such code is high. However, there are advantages to using both styles. In particular, API style migration is easier to migrate step-by-step, since it works even when implemented in both API styles. |
245 |
| - |
246 |
| -From Vue I18n v9.2, the Legacy API mode can also be used with Composition API mode. |
247 |
| - |
248 |
| -### Limitations |
249 |
| - |
250 |
| -**The Composition API in Legacy API mode does not support SSR**, So You should understand as a limited feature for migration. |
251 |
| - |
252 |
| -### How to migration |
253 |
| - |
254 |
| -#### `createI18n` |
255 |
| - |
256 |
| -You need specify `allowComposition: true` to `createI18n` otpions. the below example: |
257 |
| - |
258 |
| -```js |
259 |
| -import { createI18n } from 'vue-i18n' |
260 |
| - |
261 |
| -const i18n = createI18n({ |
262 |
| - locale: 'en', |
263 |
| - allowCompositoin: true, // you need to specify that! |
264 |
| - messages: { |
265 |
| - en: { |
266 |
| - hello: 'hello!' |
267 |
| - }, |
268 |
| - ja: { |
269 |
| - hello: 'こんにちは!' |
270 |
| - } |
271 |
| - } |
272 |
| -}) |
273 |
| - |
274 |
| -console.log(i18n.allowComposition) // output is true |
275 |
| -``` |
276 |
| - |
277 |
| -### `useI18n` in Vue Component |
278 |
| -#### `setup` option |
279 |
| - |
280 |
| -```vue |
281 |
| -<script> |
282 |
| -import { defineComponent } from 'vue' |
283 |
| -import { useI18n } from 'vue-i18n' |
284 |
| -
|
285 |
| -export default defineComponent({ |
286 |
| - name: 'Hello', |
287 |
| - setup() { |
288 |
| - const { t } = useI18n() // use as global scope |
289 |
| - return { t } |
290 |
| - } |
291 |
| -}) |
292 |
| -</script> |
293 |
| -
|
294 |
| -<template> |
295 |
| - <p>{{ $t('hello') }}</p> |
296 |
| - <p>{{ t('hello') }}</p> |
297 |
| -</template> |
298 |
| -``` |
299 |
| - |
300 |
| -#### `<script setup>` |
301 |
| - |
302 |
| -```vue |
303 |
| -<script setup> |
304 |
| -import { useI18n } from 'vue-i18n' |
305 |
| -
|
306 |
| -const { t } = useI18n() // use as global scope |
307 |
| -</script> |
308 |
| -
|
309 |
| -<template> |
310 |
| - <p>{{ $t('hello') }}</p> |
311 |
| - <p>{{ t('hello') }}</p> |
312 |
| -</template> |
313 |
| -``` |
0 commit comments