

uni-app
App has a built-in native rendering engine based on weex, which provides native rendering capabilities.
On the App side, if vue page is used, webview rendering will be used; If nvue page (abbreviation of native vue) is used, native rendering will be used. You can use two kinds of pages in an App at the same time, for example, the home page uses nvue, and the second page uses vue page, as is the case with the hello uni-app example.
Although nvue can also be compiled with multiple terminals and output H5, the css writing of nvue is limited. If you don not develop an App, nvue is not needed.
The previous weex had a big problem that it was only a high-performance renderer, and it didn't have enough API capabilities (such as various push sdk integration, Bluetooth and other capability to call), which made the development heavily dependent on the collaboration of native engineers. Developers are intended to save costs, but as a result, they need front-end, iOS and Android 3 groups of people to develop, which is counterproductive. nvue solves this problem by allowing front-end engineers to directly develop a complete App and provide rich plug-in ecosystem and cloud packaging. These combination schemes help developers to effectively improve efficiency and reduce costs.
At the same time, uni-app
expands many typesetting capabilities of weex's native rendering engine and fixes many bugs. For example
nvue's components and API are written in the same way as the vue page, and its built-in components are more than the built-in components of the vue page. See details (opens new window).
If you are familiar with weex or react native development, nvue is your better choice, which can effectively improve your development efficiency and reduce costs.
If you are a web front-end unfamiliar with native typesetting, it is recommended that you still use vue pages as the main method, and use nvue as an enhancement supplement in the case of poor performance of some vue pages on the App side. These scenarios are as follows:
list
, recycle-list
, waterfall
and other components (See details (opens new window)). The performance of these components is higher than that of the area scroll component scroll-view
in the vue page.refresh
component of nvue.swiper
+scroll-view
and the front end simulates pull-down refresh is not good. At this time, nvue is recommended. For example, the news sample template (opens new window) used in the new uni-app project achieved smooth switching by using nvue.swiper-list
in the hello uni-app template. See details (opens new window)map
, video
, and live-pusher
, you will find that the components such as view
written on the front end cannot cover the native components, and it is troublesome to deal with the level problems. It's better to use nvue at this time. Or you can also overlay a subnvue on the vue page (a non-full screen nvue page overlaid on webview) to solve the problem of native control hierarchy on App. See details (opens new window)map
component deeply, nvue is recommended. In addition to the hierarchy problem, the map function of the nvue file on the App side is more complete.video
deeply, nvue is recommended. Take the following two scenarios as an example: video is embedded in the swiper to achieve the same video sliding switch as Tik Tok, for example, see plug-in market (opens new window); After the nvue video is full screen, use cover-view
to achieve content coverage, such as adding text titles and sharing buttons.live-pusher
component under nvue, which has more complete functions and no level issues.But note that in some scenarios, nvue is not as good as vue page, as follows:
canvas
. nvue's canvas performance is not high, especially in the Android App platform. Therefore, canvas is not built in this component, but needs to be introduced separately. The highest performance way to operate canvas animation is to use the renderjs technology of vue page, as shown in the canvas example in hello uni-app.uni-app supports mixing and jumping between vue pages and nvue pages on the App side. It also supports pure nvue native rendering.
Enabling the pure native rendering mode can reduce the package size and memory usage of the App side. Because the relevant modules of webview rendering mode will be removed.
Configure "renderer":"native"
under "app-plus"
in the source view of manifest.json, which means that the pure native rendering mode is enabled on the App side. At this time, the vue page registered by pages.json will be ignored, and the vue component will be rendered by the native rendering engine.
If this value is not specified, pure native rendering will not be started by default.
// manifest.json
{
// ...
/* App platform-specific configuration */
"app-plus": {
//App side pure native rendering mode
"renderer": "native",
}
}
weex compilation mode and uni-app compilation mode
If you used to be a weex developer, you can continue to refer to this section. Otherwise, you can skip to the next section Quick Start.
weex's components and JS API are different from uni-app.
Considering the migration of weex users, uni-app also supports weex coding. You can configure to use weex compilation mode or uni-app compilation mode in manifest.json. When choosing weex compilation mode, the components of uni-app and jsapi will not be supported, and developers need to refer to the writing of weex official documents to write codes. For example, use <div>
for weex compilation mode. For uni-app compilation mode, use <view>
.
It is generally recommended to use the uni-app
mode, unless there are many historical weex codes that requires a gradual transition. At the same time, note that the switching of weex compilation mode is project level, and it is not supported to use weex mode for one nvue page and uni-app mode for another nvue page under the same project.
weex compiled mode | uni-app compilation mode | |
---|---|---|
Platform | App only | All sides, including H5 |
Component | weex components such as div | uni-app components such as view |
Lifecycle | Only weex lifecycle is supported | All uni-app lifecycles are supported |
JS API | weex API、uni API | weex API、uni API |
Unit | 750px is the screen width and wx is the fixed pixel unit | 750rpx is the screen width and px is the fixed pixel unit |
Global style | Manual introduction | The style of app.vue is the global style |
Page scrolling | Page nesting or components are necessary | Page scrolling is supported by default |
Modify the two compilation modes in manifest.json, manifest.json
-> app-plus
-> nvueCompiler
switch the compilation mode.
nvueCompiler
has two values:
// manifest.json
{
// ...
/* App platform-specific configuration */
"app-plus": {
//whether to enable uni-app mode
"nvueCompiler":"uni-app"
}
}
In the manifest.json
configuration file, the default value of HBuilderX2.4+ is weex
mode, but the default value of HBuilderX2.4+ is changed to uni-app
mode.
weex compilation mode does not support the writing of onNavigationBarButtonTap
life cycle functions. listen to the native title bar button click event in nvue, see: uni.onNavigationBarButtonTap (opens new window) for details.
The weex compilation mode does not support the onShow lifecycle.
weex compilation mode does not support vuex
.
Unlike weex, the page jump of nvue still follows the routing model of uni-app. The model is followed no matter how you jump between vue page and nvue page. Including nvue page jumping to nvue page. Each page needs to be registered in pages.json and call uni-app's route API (opens new window) to jump.
Native development does not have the concept of page scrolling. When the page content is higher than the screen height, the content will not automatically scroll; Only the content of the page is placed under the components of list
, waterfall
, and scroll-view/scroller
can be scrolled. This is not in line with the custom of front-end development, so when nvue is compiled into the uni-app
mode, the uni-app
framework will automatically nest an scroller
in the outer layer of the nvue page, so as to realize the automatic scrolling of the page content.
Notice:
uni-app
frame only nests the scroller
container for the nvue page, and does not automatically nest the scroller
container for the component;recycle-list
component on the nvue page, the uni-app
frame will not automatically nest the scroller
container on the page.scroller
container, you can turn it off in pages.json
with the following configuration:{
"path": "",
"style": {
// scroller is not nested
"disableScroll": true
}
}
weex ui is supported in weex compilation mode. For example, See details (opens new window). But compared to the uni-app plug-in market and official uni ui (opens new window), the component ecology of weex syntax is still relatively lacking.
From HBuilderX 3.1.0+, new style compilation mode is supported
// manifest.json
{
// ...
/* App platform-specific configuration */
"app-plus": {
"nvueStyleCompiler": "uni-app"
}
}
In the uni-app
project of HBuilderX, create a new page and pop up the upper right corner of the interface, you can choose whether to create the vue
page or the nvue
page, or both at the same time.
Both vue page and nvue page need to be registered in pages.json
. If you create a new page in HBuilderX, it will be registered automatically, if you use other editors, you need to register it in pages.json.
If there are both vue pages and nvue pages under a page route, there will be the vue and nvue files with the same name. Then on the App side, only nvue pages will be used, and the vue file with the same name will not be compiled to the App side. While on the non-App side, the vue page is preferred.
If there are different names and there are only nvue pages, on non-app sides, only the nvue files in uni-app compilation mode will be compiled.
nvue
is the same as vue
in terms of the page structure, which is composed of template
, style
, and script
.
HBuilderX has built-in an enhanced version of the weex debugging tool, including reviewing interface elements, watching log, and debugging breakpoints. See details (opens new window)
From HBuilder X 3.1.0+, nvue has added the render-whole
attribute and typeBoolean
.
Enable render-whole
as a component list of true
by default
text
cell
header
cell-slot
recycle-list
Usage
<swiper :render-whole="true"></swiper>
Demo
The effect of this demonstration on Android version 5.1 mobile phone is not so obvious in higher version mobile phone
For the sample project, Click to download (opens new window)
Rendering based on native engine is still a front-end technology stack, but it is definitely different from web development.
v-if
but not v-show
flex
layout and does not support any other layout methods. Before developing the page, you should first figure out what the vertical content of this page is and which contents are to be scrolled, then what is the horizontal axis arrangement of each vertical content, and design the interface according to flex layout.column
). If you need to change the layout direction, you can modify it under the node manifest.json
-> app-plus
-> nvue
-> flex-direction
, which only takes effect in uni-app mode. Details. (opens new window)display:flex
, its flex direction is horizontal instead of vertical by default. Therefore, when nvue is compiled into H5, the default layout of the page will be set to flex and the direction will be vertical automatically. Of course, the default settings will be overridden after the developer sets them manually.<text>
component. You cannot write text directly in the text
area of <div>
and <view>
. Otherwise, even if rendered, the variables in js cannot be bound.text
tag can set the font size and font color.flex
is still very powerful. See detailsimage
components and levels to achieve background effects similar to those in the web. Because in native development, there is no such concept of background map like web.background-color
is not set, ghosting problems may occur.class
only supports array syntax when binding.bounce
rebound effect, only a few list components have the bounce
effect, including list
, recycle-list
, and waterfall
.list
, waterfall
, scroll-view/scroller
). The content to be scrolled needs to be set under the scrollable component. This is not in line with the habit of front-end development, so when nvue is compiled into uni-app mode, an scroller
is automatically nested to the outer layer of the page, and the page content will automatically scroll if it is too high. (The component will not be nested, nor will it be nested when there is recycle-list
on the page). Follow-up configuration will be provided, and the function can be set not to be applied automatically.globalData
and vuex
are effective.APP-NVUE
style
. For the use of font icons in nvue, please refer to: Load custom fonts.typescript/ts
is currently not supported on the nvue page.json
. It takes little time to draw the native navigation bar, but it takes much longer to draw the whole page by analyzing the js of nvue, especially when the new page enters the animation period. For complex pages, there is no native navigation bar that will generate the white screen or splash screen of the whole screen during the animation period.By default, when the content of the scrolling container component (such as list
, waterfall
components) on the iOS platform is insufficient, it will not be able to scroll up and down because the visible area of the container is not filled. At this time, the pull-down refresh function cannot be operated, and the @refresh
and @pullingdown
events of the refresh
component cannot be triggered. At this time, you can configure the alwaysScrollableVertical
property value in the container component to set the value of true
to support up and down scrolling and pull-down refresh operations.
<list class="scroll-v list" enableBackToTop="true" scroll-y alwaysScrollableVertical="true">
<refresh class="refresh" @refresh="onrefresh()" @pullingdown="onpullingdown">
//refresh content
</refresh>
<cell v-for="(newsitem,index) in list" :key="newsitem.id">
//cell content
</cell>
</list>
Android platform does not have this problem