vue
uni-app x的vue规范,按照vue3规范实现,但目前不支持setup组合式写法,仅支持option选项式写法。
本文暂时只包括兼容性表格,vue功能详情另见 vue3概述、Vue3 API。
全局 API兼容性
应用实例
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
app.component() | 5.0 | √ | √ | 10.0 | √ | x |
app.directive() | 5.0 | √ | x | 10.0 | √ | x |
app.use() | 5.0 | √ | x | 10.0 | √ | x |
app.mixin() | 5.0 | √ | x | 10.0 | √ | x |
app.provide() | 5.0 | √ | x | 10.0 | √ | x |
app.config | 5.0 | √ | √ | 10.0 | √ | x |
app.config.errorHandler | 5.0 | √ | x | 10.0 | √ | x |
app.config.warnHandler | 5.0 | √ | x | 10.0 | √ | x |
app.config.performance | 5.0 | √ | x | 10.0 | √ | x |
app.config.globalProperties | 5.0 | √ | x | 10.0 | √ | x |
app.config.optionMergeStrategies | 5.0 | √ | x | 10.0 | √ | x |
通用
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
nextTick() | 5.0 | x | √ | 10.0 | x | x |
defineComponent() | 5.0 | x | x | 10.0 | x | x |
defineAsyncComponent() | 5.0 | x | x | 10.0 | x | x |
响应式兼容性
响应式: 核心
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
ref() | 5.0 | √ | √ | 10.0 | √ | x |
computed() | 5.0 | √ | x | 10.0 | √ | x |
reactive() | 5.0 | √ | √ | 10.0 | √ | x |
readonly() | 5.0 | √ | x | 10.0 | √ | x |
watchEffect() | 5.0 | √ | x | 10.0 | √ | x |
watch() | 5.0 | √ | x | 10.0 | √ | x |
响应式: 工具
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
isRef() | 5.0 | √ | x | 10.0 | √ | x |
unref() | 5.0 | √ | x | 10.0 | √ | x |
toRef() | 5.0 | √ | x | 10.0 | √ | x |
toRefs() | 5.0 | √ | x | 10.0 | √ | x |
isProxy() | 5.0 | √ | x | 10.0 | √ | x |
isReactive() | 5.0 | √ | x | 10.0 | √ | x |
isReadonly() | 5.0 | √ | x | 10.0 | √ | x |
响应式: 进阶
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
shallowRef() | 5.0 | √ | x | 10.0 | √ | x |
triggerRef() | 5.0 | √ | x | 10.0 | √ | x |
customRef() | 5.0 | √ | x | 10.0 | √ | x |
shallowReactive() | 5.0 | √ | x | 10.0 | √ | x |
shallowReadonly() | 5.0 | √ | x | 10.0 | √ | x |
toRaw() | 5.0 | √ | x | 10.0 | √ | x |
markRaw() | 5.0 | √ | x | 10.0 | √ | x |
指令
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
v-text | 5.0 | √ | √ | 10.0 | √ | x |
v-html | 5.0 | √ | x | 10.0 | √ | x |
v-show | 5.0 | √ | √ | 10.0 | √ | x |
v-if | 5.0 | √ | √ | 10.0 | √ | x |
v-else | 5.0 | √ | √ | 10.0 | √ | x |
v-else-if | 5.0 | √ | √ | 10.0 | √ | x |
v-for | 5.0 | √ | √ | 10.0 | √ | x |
v-on | 5.0 | √ | √ | 10.0 | √ | x |
v-bind | 5.0 | √ | √ | 10.0 | √ | x |
v-model | 5.0 | √ | √ | 10.0 | √ | x |
v-slot | 5.0 | √ | √ | 10.0 | √ | x |
v-pre | 5.0 | √ | x | 10.0 | √ | x |
v-once | 5.0 | √ | x | 10.0 | √ | x |
v-memo | 5.0 | x | x | 10.0 | x | x |
v-cloak | 5.0 | x | x | 10.0 | x | x |
事件处理
script
- 仅支持
export default {}
方式定义组件。 data
仅支持函数返回对象字面量方式。
应用生命周期
uni-app x 新增了 onLastPageBackPress 和 onExit 应用级生命周期,Android退出应用逻辑写在app.uvue里,新建项目的模板自动包含相关代码。如需修改退出逻辑,请直接修改相关代码。
组件
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
<Transition> | 5.0 | x | x | 10.0 | x | x |
<TransitionGroup> | 5.0 | x | x | 10.0 | x | x |
<KeepAlive> | 5.0 | x | x | 10.0 | x | x |
<Teleport> | 5.0 | x | x | 10.0 | x | x |
特殊元素
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
<component> | 5.0 | √ | x | 10.0 | √ | x |
<slot> | 5.0 | √ | √ | 10.0 | √ | x |
<template> | 5.0 | √ | √ | 10.0 | √ | x |
- App 端,如需页面级滚动,根节点必须是
scroll-view
标签。
特殊 Attributes
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
key | 5.0 | √ | √ | 10.0 | √ | x |
ref | 5.0 | √ | √ | 10.0 | √ | x |
is | 5.0 | √ | x | 10.0 | √ | x |
生命周期选项
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
beforeCreate | 5.0 | √ | √ | 10.0 | √ | x |
created | 5.0 | √ | √ | 10.0 | √ | x |
beforeMount | 5.0 | √ | √ | 10.0 | √ | x |
mounted | 5.0 | √ | √ | 10.0 | √ | x |
beforeUpdate | 5.0 | √ | √ | 10.0 | √ | x |
updated | 5.0 | √ | √ | 10.0 | √ | x |
beforeUnmount | 5.0 | √ | √ | 10.0 | √ | x |
unmounted | 5.0 | √ | √ | 10.0 | √ | x |
errorCaptured | 5.0 | √ | x | 10.0 | √ | x |
renderTracked | 5.0 | √ | x | 10.0 | √ | x |
renderTriggered | 5.0 | √ | x | 10.0 | √ | x |
activated | 5.0 | √ | x | 10.0 | √ | x |
deactivated | 5.0 | √ | x | 10.0 | √ | x |
插件
暂不支持vue插件,比如pinia、vuex、i18n、router。简单的状态管理可以参考文档全局变量和状态管理。
选项式 API兼容性
状态选项
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
data | 5.0 | √ | √ | 10.0 | √ | x |
props | 5.0 | √ | √ | 10.0 | √ | x |
computed | 5.0 | √ | √ | 10.0 | √ | x |
methods | 5.0 | √ | √ | 10.0 | √ | x |
watch | 5.0 | √ | √ | 10.0 | √ | x |
emits | 5.0 | √ | √ | 10.0 | √ | x |
渲染选项
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
template | 5.0 | x | x | 10.0 | x | x |
render | 5.0 | x | x | 10.0 | x | x |
组合选项
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
provide | 5.0 | √ | x | 10.0 | √ | x |
inject | 5.0 | √ | x | 10.0 | √ | x |
mixins | 5.0 | √ | x | 10.0 | √ | x |
extends | 5.0 | √ | x | 10.0 | √ | x |
其他杂项
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
name | 5.0 | √ | √ | 10.0 | √ | x |
inheritAttrs | 5.0 | √ | √ | 10.0 | √ | x |
components | 5.0 | √ | √ | 10.0 | √ | x |
directives | 5.0 | √ | x | 10.0 | √ | x |
组件实例
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
$data | 5.0 | √ | √ | 10.0 | √ | x |
$props | 5.0 | √ | √ | 10.0 | √ | x |
$el | 5.0 | x | √ | 10.0 | x | x |
$options | 5.0 | √ | √ | 10.0 | √ | x |
$parent | 5.0 | √ | √ | 10.0 | √ | x |
$root | 5.0 | √ | √ | 10.0 | √ | x |
$slots | 5.0 | x | √ | 10.0 | √ | x |
$refs | 5.0 | √ | √ | 10.0 | √ | x |
$attrs | 5.0 | √ | √ | 10.0 | √ | x |
$watch() | 5.0 | √ | √ | 10.0 | √ | x |
$emit | 5.0 | √ | √ | 10.0 | √ | x |
$forceUpdate | 5.0 | √ | x | 10.0 | √ | x |
$nextTick | 5.0 | √ | √ | 10.0 | √ | x |
$callMethod | 5.0 | x | √ | 10.0 | x | x |
进阶 API兼容性
渲染函数
| 安卓系统版本 | 安卓 uni-app | 安卓 uni-app-x | iOS 系统版本 | iOS uni-app | iOS uni-app-x |
h() | 5.0 | x | x | 10.0 | x | x |
resolveComponent() | 5.0 | x | √ | 10.0 | x | x |
resolveDirective() | 5.0 | x | x | 10.0 | x | x |
withDirectives() | 5.0 | x | √ | 10.0 | x | x |