The js API of uni-app consists of standard ECMAScript js API and uni extension API.

Standard ECMAScript js is only the most basic js. The browser extends window, document, navigator and other objects based on it. The applet also extends various APIs of wx.xx, my.xx, and swan.xx based on standard js. Node also extends modules such as fs.

uni-app extends uni objects based on ECMAScript, and the API naming remains compatible with applets.

# Difference between standard js and browser js

The js code of uni-app, the h5 side runs in the browser. For non-h5 terminals (including applets and apps), the Android platform runs in the v8 engine, and the iOS platform runs in the jscore engine that comes with iOS, and neither runs in the browser or webview.

On the non-H5 side, although it does not support the js API of browsers such as window, document, and navigator, it also supports standard ECMAScript.

Be careful not to equate js extension objects in browsers with standard js.

Therefore, the non-H5 side of uni-app also supports standard js, syntax such as if and for, variable types such as strings, numbers, time, Boolean values, arrays, custom objects, and various processing methods. It's just that browser-specific objects such as window, document, and navigator are not supported.

# Supported on ES6

uni-app supports not only most ES6 API, but also await/async of ES7.

For the support of ES6 API, see the following table for details (x means no support, and no special instructions means support):

  • Because the third-party js engine is not allowed on iOS, there is no distinction between App, applet, and H5 on iOS, and each terminal only depends on the iOS version.

  • Differences can be seen among Android versions of various sides:

    • The data on the App side is shown in the table below;
    • See caniuse for H5 data;
    • WeChat Mini Program [see details](https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/js-support.html#%E5%AE%A2%E6%88%B7%E7% AB%AF%20ES6%20API%20%E6%94%AF%E6%8C%81%E6%83%85%E5%86%B5)
    • Ali Mini Program see details
    • 百度小程序详见
    • 抖音小程序详见
    • QQ Mini Program [see details](https://q.qq.com/wiki/develop/miniprogram/frame/useful/useful_env.html#es6%E6%94%AF%E6%8C%81%E6%83 %85%E5%86%B5)
String iOS8 iOS9 iOS10 Android
codePointAt
includes
startsWith
endsWith
repeat
String.fromCodePoint
Array iOS8 iOS9 iOS10 Android
copyWithin
find
findIndex
fill
entries
keys
values x x
includes x
Array.from
Array.of
Number iOS8 iOS9 iOS10 Android
isFinite
isNaN
parseInt
parseFloat
isInteger
EPSILON
isSafeInteger
Math iOS8 iOS9 iOS10 Android
trunc
sign
cbrt
clz32
imul
fround
hypot
expm1
log1p
log10
log2
sinh
cosh
tanh
asinh
acosh
atanh
Object iOS8 iOS9 iOS10 Android
is
assign
getOwnPropertyDescriptor
keys
getOwnPropertyNames
getOwnPropertySymbols
Other iOS8 iOS9 iOS10 Android<5
Symbol
Set
Map
Proxy x x x
Reflect
Promise

注意

  • 默认不需要在微信工具里继续开启es6转换。但如果用了微信的wxml自定义组件(wxcomponents目录下),uni-app编译器并不会处理这些文件中的es6代码,需要去微信工具里开启转换。从HBuilderX调起微信工具时,如果发现工程下有wxcomponents目录会自动配置微信工程打开es6转换。

# App端

在App端JS脚本运行在独立的JS引擎中,vue页面使用系统webview渲染,nvue页面使用系统原生View渲染。

# Android平台

  • JS脚本运行在独立Google V8引擎中,版本与Chrome83一致,因此支持的语法与Android系统版本无关,即便是Android4.4也与Chrome83支持的语法一样。 可到MDN网站查看浏览器兼容性,Chrome83支持的在Android平台也支持。
  • vue页面渲染在系统Webview中,受Android系统版本影响,在Android低端机上存在css浏览器兼容性问题,太新的css语法在低版本不支持。当然也可以使用x5等三方webview来拉齐实现。
  • nvue页面使用系统原生View渲染,css支持情况参考:nvue页面样式

# iOS平台

  • JS脚本运行在iOS操作系统提供的JavaScriptCore 引擎,因此支持的语法与iOS系统有关,跟iOS系统的Safari浏览器一致。 可到MDN网站查看浏览器兼容性,兼容性与Safari on iOS一致。
  • vue页面渲染在系统WKWebview中,受iOS系统版本影响,兼容性与iOS系统的Safari浏览器一致。
  • nvue页面使用系统原生View渲染,css支持情况参考:nvue页面样式

# 部分兼容性示例

正则反向预查 ?<= ?<!,iOS16.4+支持