从 Ionic 6 更新到 7
¥Updating from Ionic 6 to 7
本指南假设你已将应用更新到最新版本的 Ionic 6。在开始本指南之前,请确保你已遵循 升级到 Ionic 6 指南。
¥This guide assumes that you have already updated your app to the latest version of Ionic 6. Make sure you have followed the Upgrading to Ionic 6 Guide before starting this guide.
有关从 Ionic 6 到 Ionic 7 的重大更改的完整列表,请参阅 Ionic 框架存储库中的 重大变更文档。
¥For a complete list of breaking changes from Ionic 6 to Ionic 7, please refer to the breaking changes document in the Ionic Framework repository.
新手上路
¥Getting Started
Angular
-
Ionic 7 支持 Angular 14+。按照 角度更新指南 更新到最新版本的 Angular。
¥Ionic 7 supports Angular 14+. Update to the latest version of Angular by following the Angular Update Guide.
-
如果你的项目使用 rxjs,Ionic 7 需要的最低 rxjs 版本为 7.5.0:
¥If your project is using rxjs, Ionic 7 requires a minimum rxjs version of 7.5.0:
npm install rxjs@7.5.0
-
更新到最新版本的 Ionic 7:
¥Update to the latest version of Ionic 7:
npm install @ionic/angular@7
如果你正在使用 Ionic Angular Server 和 Ionic Angular Toolkit,请务必同时更新它们:
¥If you are using Ionic Angular Server and Ionic Angular Toolkit, be sure to update those as well:
npm install @ionic/angular@7 @ionic/angular-server@7 @ionic/angular-toolkit@9
注意:
@ionic/angular-toolkit@9要求角度至少为 15。如果你仍在使用 Angular 14,那么你可以跳过更新到@ionic/angular-toolkit@9。¥Note:
@ionic/angular-toolkit@9requires a minimum of Angular 15. If you are still on Angular 14, then you can skip updating to@ionic/angular-toolkit@9.
React
-
Ionic 7 支持 React 17+。更新到最新版本的 React:
¥Ionic 7 supports React 17+. Update to the latest version of React:
npm install react@latest react-dom@latest
-
更新到最新版本的 Ionic 7:
¥Update to the latest version of Ionic 7:
npm install @ionic/react@7 @ionic/react-router@7
Vue
-
Ionic 7 支持 Vue 3.0.6+。更新到最新版本的 Vue:
¥Ionic 7 supports Vue 3.0.6+. Update to the latest version of Vue:
npm install vue@latest vue-router@latest
-
更新到最新版本的 Ionic 7:
¥Update to the latest version of Ionic 7:
npm install @ionic/vue@7 @ionic/vue-router@7
核心
¥Core
-
更新到最新版本的 Ionic 7:
¥Update to the latest version of Ionic 7:
npm install @ionic/core@7
更新你的代码
¥Updating Your Code
浏览器支持
¥Browser Support
Ionic 支持的浏览器列表已更改。查看 浏览器支持指南 以确保你将应用部署到支持的浏览器。
¥The list of browsers that Ionic supports has changed. Review the Browser Support Guide to ensure you are deploying apps to supported browsers.
如果你有 browserslist 或 .browserslistrc 文件,请使用以下内容更新它:
¥If you have a browserslist or .browserslistrc file, update it with the following content:
Chrome >=79
ChromeAndroid >=79
Firefox >=70
Edge >=79
Safari >=14
iOS >=14
类型
¥Types
-
ActionSheetAttributes、AlertAttributes、AlertTextareaAttributes、AlertInputAttributes、LoadingAttributes、ModalAttributes、PickerAttributes、PopoverAttributes和ToastAttributes已被删除。开发者应该使用{ [key: string]: any }。¥
ActionSheetAttributes,AlertAttributes,AlertTextareaAttributes,AlertInputAttributes,LoadingAttributes,ModalAttributes,PickerAttributes,PopoverAttributes, andToastAttributeshave been removed. Developers should use{ [key: string]: any }instead.
复选框
¥Checkbox
-
将
--background和--background-checkedCSS 变量的任何用法分别重命名为--checkbox-background和--checkbox-background-checked。¥Rename any usages of the
--backgroundand--background-checkedCSS Variables to--checkbox-backgroundand--checkbox-background-checked, respectively.
日期时间
¥Datetime
-
删除将
value属性设置为空字符串 ('') 的任何代码。¥Remove any code that sets the
valueproperty to the empty string (''). -
删除访问
value属性上的时区信息的任何代码。Datetime 不管理时区, 因此提供的任何时区信息都将被忽略。¥Remove any code that accesses the time zone information on the
valueproperty. Datetime does not manage time zones, so any time zone information provided is ignored.
输入
¥Input
-
将访问
ionInput事件的detail有效负载的任何代码从event.detail更新为event.detail.value,因为详细有效负载现在是包含值和事件的对象。¥Update any code that accesses the
detailpayload for theionInputevent fromevent.detailtoevent.detail.valueas the detail payload is now an object containing a value and an event.
模态
¥Modal
-
删除
swipeToClose属性的任何使用。默认情况下,卡片模态是可滑动的,因此如果你希望卡片模态保持可滑动,你可以删除swipeToClose。如果你想防止模式关闭,请使用 canDismiss 属性。¥Remove any usage of the
swipeToCloseproperty. Card modals are swipeable by default, so you can removeswipeToCloseif you want your card modal to remain swipeable. Use the canDismiss property if you want to prevent a modal from dismissing. -
删除将
canDismiss属性设置为undefined的任何代码。canDismiss属性现在默认为true,因此不再需要此代码。¥Remove any code that sets the
canDismissproperty toundefined. ThecanDismissproperty now defaults totrue, so this code is no longer needed.
拾取器
¥Picker
-
删除在
ion-picker-column上访问refresh的任何代码。开发者应使用ion-picker上的columns属性来刷新视图。¥Remove any code that accesses
refreshonion-picker-column. Developers should use thecolumnsproperty onion-pickerto refresh the view instead.
搜索栏
¥Searchbar
-
将访问
ionInput事件的detail有效负载的任何代码从event.detail更新为event.detail.value,因为详细有效负载现在是包含值和事件的对象。¥Update any code that accesses the
detailpayload for theionInputevent fromevent.detailtoevent.detail.valueas the detail payload is now an object containing a value and an event.
片段
¥Segment
-
删除将
value属性设置为null的任何代码。开发者应使用''或undefined。¥Remove any code that sets the
valueproperty tonull. Developers should use either''orundefinedinstead.
幻灯片
¥Slides
-
删除
ion-slides、ion-slide和任何关联的类型。这些组件已被删除,以便直接使用 Swiper.js。以下指南包含有关此迁移的更多信息:¥Remove
ion-slides,ion-slide, and any associated types. These components have been removed in favor of using Swiper.js directly. The guides below contain more information about this migration:
¥Angular Migration Guide
React Migration Guide
Vue Migration Guide
文本区
¥Textarea
-
将访问
ionInput事件的detail有效负载的任何代码从event.detail更新为event.detail.value,因为详细有效负载现在是包含值和事件的对象。¥Update any code that accesses the
detailpayload for theionInputevent fromevent.detailtoevent.detail.valueas the detail payload is now an object containing a value and an event.
切换
¥Toggle
-
将
--background和--background-checkedCSS 变量的任何用法分别重命名为--track-background和--track-background-checked。¥Rename any usages of the
--backgroundand--background-checkedCSS Variables to--track-backgroundand--track-background-checked, respectively.
虚拟滚动
¥Virtual Scroll
-
删除
ion-virtual-scroll和任何关联的类型。该组件已被删除,以支持使用 JavaScript 框架提供的虚拟滚动解决方案。以下指南包含有关此迁移的更多信息:¥Remove
ion-virtual-scrolland any associated types. This component has been removed in favor of using virtual scroll solutions provided by JavaScript Frameworks. The guides below contain more information about this migration:
¥Angular Migration Guide
React Migration Guide
Vue Migration Guide
需要升级帮助吗?
¥Need Help Upgrading?
请务必查看 Ionic 7 重大变更指南。开发者可能需要注意默认属性和 CSS 变量值的一些更改。此页面仅列出需要用户操作的重大更改。
¥Be sure to look at the Ionic 7 Breaking Changes Guide. There were several changes to default property and CSS Variable values that developers may need to be aware of. Only the breaking changes that require user action are listed on this page.
如果你需要升级帮助,请在 Ionic 论坛 上发布帖子。
¥If you need help upgrading, please post a thread on the Ionic Forum.