|
1 | 1 | # Vue 3 迁移指南
|
2 | 2 |
|
3 |
| -本指南主要针对有 Vue 2经验的用户,他们希望了解 Vue 2和 Vue 3之间的变化。 **在使用 Vue 3之前,你不需要从头到尾阅读这篇文章。** 学习 Vue 3的推荐方法是阅读[新的文档](https://cn.vuejs.org)。 |
| 3 | +本指南主要针对有 Vue 2经验的用户,他们希望了解 Vue 2和 Vue 3之间的变化。**在使用 Vue 3之前,你不需要从头到尾阅读这篇文章**。学习 Vue 3的推荐方法是阅读[新的文档](https://cn.vuejs.org)。 |
4 | 4 |
|
5 |
| -<!-- TODO --> |
| 5 | +<!-- VueMastery Start --> |
| 6 | +<style> |
| 7 | +.vue-mastery-link { |
| 8 | + background-color: #f9f9f9; |
| 9 | + border-radius: 8px; |
| 10 | + padding: 8px 16px 8px 8px; |
| 11 | +} |
| 12 | + |
| 13 | +.vue-mastery-link a { |
| 14 | + display: flex; |
| 15 | + align-items: center; |
| 16 | + text-decoration: none; |
| 17 | +} |
| 18 | + |
| 19 | +.vue-mastery-link .banner { |
| 20 | + background-color: #f9f9f9; |
| 21 | + border-radius: 4px; |
| 22 | + width:96px; |
| 23 | + height:56px; |
| 24 | + object-fit: cover; |
| 25 | +} |
| 26 | + |
| 27 | +.vue-mastery-link .description { |
| 28 | + flex: 1; |
| 29 | + font-weight: 500; |
| 30 | + font-size: 14px; |
| 31 | + line-height: 20px; |
| 32 | + color: #213547; |
| 33 | + margin: 0 0 0 16px; |
| 34 | +} |
| 35 | + |
| 36 | +.vue-mastery-link .description span { |
| 37 | + color: #42b883; |
| 38 | +} |
| 39 | + |
| 40 | +.vue-mastery-link .logo-wrapper { |
| 41 | + position: relative; |
| 42 | + width: 48px; |
| 43 | + height: 48px; |
| 44 | + border-radius: 50%; |
| 45 | + background-color: #ffffff; |
| 46 | + display: flex; |
| 47 | + justify-content: center; |
| 48 | + align-items: center; |
| 49 | +} |
| 50 | + |
| 51 | +.vue-mastery-link .logo-wrapper img { |
| 52 | + width: 25px; |
| 53 | + object-fit: contain; |
| 54 | +} |
| 55 | + |
| 56 | +@media (max-width: 576px) { |
| 57 | + .vue-mastery-link .banner { |
| 58 | + width:56px; |
| 59 | + } |
| 60 | + |
| 61 | + .vue-mastery-link .description { |
| 62 | + font-size: 12px; |
| 63 | + line-height: 18px; |
| 64 | + } |
| 65 | + .vue-mastery-link .logo-wrapper { |
| 66 | + position: relative; |
| 67 | + width: 32px; |
| 68 | + height: 32px; |
| 69 | + } |
| 70 | +} |
| 71 | +</style> |
| 72 | + |
| 73 | +<div class="vue-mastery-link"> |
| 74 | + <a href="https://www.vuemastery.com/migration-guide-cheat-sheet/" target="_blank"> |
| 75 | + <div class="banner-wrapper"> |
| 76 | + <img class="banner" alt="Vue Mastery banner" width="96px" height="56px" src="https://storage.googleapis.com/vue-mastery.appspot.com/flamelink/media/vuemastery-graphical-link-96x56.png" /> |
| 77 | + </div> |
| 78 | + <p class="description">Get the free Migration Guide Cheat Sheet at <span>VueMastery.com</span></p> |
| 79 | + <div class="logo-wrapper"> |
| 80 | + <img alt="Vue Mastery Logo" width="25px" src="https://storage.googleapis.com/vue-mastery.appspot.com/flamelink/media/vue-mastery-logo.png" /> |
| 81 | + </div> |
| 82 | + </a> |
| 83 | +</div> |
| 84 | +<!-- VueMastery End --> |
| 85 | + |
| 86 | +<style> |
| 87 | +.note { |
| 88 | + color: #476582; |
| 89 | +} |
| 90 | +</style> |
| 91 | + |
| 92 | +## 值得注意的新特性 |
| 93 | + |
| 94 | +Vue 3中需要关注的一些新特性包括: |
| 95 | + |
| 96 | +- [组合式 API](https://vuejs.org/guide/extras/composition-api-faq.html)<span class="note">\*</span> |
| 97 | +- [单文件组件,组合式 API 语法糖 (`<script setup>`)](https://vuejs.org/api/sfc-script-setup.html)<span class="note">\*</span> |
| 98 | +- [Teleport 组件](https://vuejs.org/guide/built-ins/teleport.html) |
| 99 | +- [Fragments 片段](/new/fragments.html) |
| 100 | +- [Emits 组件选项](https://vuejs.org/api/options-state.html#emits)<span class="note">\*\*</span> |
| 101 | +- [`createRenderer` API from `@vue/runtime-core`](https://vuejs.org/api/custom-renderer.html) 用来创建自定义渲染函数 |
| 102 | +- [单文件组件,状态绑定 CSS 变量(`v-bind` in `<style>`)](https://vuejs.org/api/sfc-css-features.html#v-bind-in-css)<span class="note">\*</span> |
| 103 | +- [SFC `<style scoped>` 新增全局规则和针对插槽内容规则](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0023-scoped-styles-changes.md) |
| 104 | +- [Suspense](https://vuejs.org/guide/built-ins/suspense.html) <sup class="warning">实验性</sup> |
| 105 | + |
| 106 | +<sub class="note"><b>\*</b> 现在也支持在 <a href="https://blog.vuejs.org/posts/vue-2-7-naruto.html" target="_blank">Vue 2.7</a></sub><br> |
| 107 | +<sub class="note"><b>\*\*</b> Vue 2.7 中支持, 但仅用于类型推断</sub> |
| 108 | + |
| 109 | +## 非兼容性改变 |
| 110 | + |
| 111 | +列出了Vue 2和Vue 3之间的非兼容性更改 [这里](/breaking-changes/)。 |
| 112 | + |
| 113 | +## 新的框架级别推荐 |
| 114 | + |
| 115 | +列出了新的框架级建议 [这里](/recommendations)。 |
| 116 | + |
| 117 | +## 迁移构建 |
| 118 | + |
| 119 | +如果您有一个现有的Vue 2项目或库,并打算将其升级到 Vue 3,我们将提供一个 Vue 3的构建版本,它提供与 Vue 2兼容的 api。查看 [迁移构建](/migration-build) 页面了解更多细节。 |
0 commit comments