English
Each end has its own characteristics, some can be smoothed, and some cannot be smoothed.
Note: cross-end, not to migrate the web habits to the whole platform. Instead, it is written according to uni, and then used on all platforms.
Non-H5 end does not support * selector;
Please change the element selector of body to page, similarly, change div, ul and li to view, span and font to text, a to navigator, img to image...
The non-H5 side does not enable scoped by default. If you need to isolate the component style, you can add the scoped attribute to the style tag. The H5 side enables scoped by default in order to isolate the styles between pages.
The vue page is on the App side, and it is rendered by the system's webview by default (not the mobile phone's own browser, but the rom's webview). On older mobile phones, such as Android4.4, 5.0 or iOS8, many css are not supported , so don't use too new css, it will cause abnormal interface.
Note that this does not mean that flex cannot be used, Android4.4 also supports flex, just don't use too new css.
You can find an Android 4.4 mobile phone or use a pc emulator to actually test it. Most domestic Android emulators are 4.4 or 5.0.
Starting from uni-app 2.5.3, the Android side supports the introduction of the Tencent x5 browser kernel, which can smooth out the browser compatibility issues of low-end Android, [see the x5 user guide for details](https://ask.dcloud.net. cn/article/36806)
The MiniApp does not have browser compatibility issues, and it comes with a large Webview. So if your H5 and MiniApp interfaces are normal, but the Android low-end app interface is abnormal, and the app does not use the x5 engine, it can basically be determined that it is because of css compatibility.
The nvue page on the app side does not have browser compatibility issues. It comes with a unified native rendering engine and does not rely on webview.
The webview corresponding to Android4.4 is chrome37. For details of the browser kernels at each end, refer to: About the difference and compatibility of mobile phone webview kernel, default browser, and rendering layer browsers of various MiniApp
If your code does not use these directly, it is likely that the imported third-party library uses these. If it is the latter, go to the plug-in market to search for alternatives. You should know that the js on the non-H5 side runs under an independent js core or v8, not in the browser.
From HBuilderX 2.6, renderjs has been added on the App side, which is a js running in the view layer. Vue pages can operate browser objects through renderjs, and then allow browser-based libraries to run directly on the App side of uni-app , such as echart, threejs, see: renderjs
url(//alicdn.net)
to url(https://alicdn.net)
, because // on the App side is a file protocol###The possibility that the MiniApp is normal but the App is abnormal The rendering engine of Vue pages on the App side defaults to the system webview (not the mobile phone's own browser, but the rom's webview). On older mobile phones, such as Android4.4, 5.0 or iOS8, some new css syntax is not supported of. Note that this does not mean that flex cannot be used, Android4.4 also supports flex, just don't use too new css. You can find an Android 4.4 mobile phone or use a pc emulator to actually test it. Most domestic Android emulators are 4.4 or 5.0.
The MiniApp does not have browser compatibility issues, and it has dozens of built-in custom webviews of its own. So if your H5 and MiniApp interfaces are normal, but the App interface is abnormal, it is mostly because of css compatibility.
Solve problems like this:
uni-app
is implemented based on Vue 2.0
. Developers should pay attention to the usage differences of Vue 1.0 -> 2.0. For details, see [Migration from Vue 1.x](https://cn.vuejs.org/v2/ guide/migration.html)
The data attribute must be declared as a function that returns an initial data object; otherwise, when the page is closed, the data will not be automatically destroyed, and when the page is opened again, the last data will be displayed
//Correct usage, use function to return object
data() {
return {
title: 'Hello'
}
}
//Incorrect writing will cause the last data to be displayed when the page is opened again
data: {
title: 'Hello'
}
On the WeChat MiniApp side, uni-app
entrusts the data binding function to Vue
, and developers need to implement data binding according to Vue 2.0
, which does not support the data binding method of WeChat MiniApp. Therefore, the following writing is not supported:
<view id="item-{{id}}"></view>
Need to be changed to:
<view v-bind:id="'item-' + id "></view>
You may have been used to free web development before, but currently there are many restrictions on various MiniApp. Of course, the limitation is to better optimize the user experience at the framework layer, so the experience of MiniApp is better than that of web. And these restrictions are only limitations of writing, and do not affect the function. If you have done WeChat MiniApp development, you should already be familiar with these limitations. If you have never done a MiniApp, please read this section carefully.
pages
directory; recommended solution: create a new page directory, and then create a .vue
file with the same name as the directory, such as /pages/list/list.vue
, and then add it to pages.json
to complete the registration. This is the same strategy as for MiniApp.component
directorystatic
directory. Here are the rules for webpack
uni-app
is implemented based on Vue 2.0
, developers should pay attention to the usage differences of Vue 1.0 -> 2.0, see [Migration from Vue 1.x](https://cn .vuejs.org/v2/guide/migration.html)H5 published to the server Note:
manifest.json
file, and add the base attribute under the router to html5
unpackage/dist/build/web
目录找到出的资源,部署服务器(或者使用本地服务器预览),如需部署到相对路径(Vue2 项目支持本地file协议打开)参考:https://ask.dcloud.net.cn/article/37432。
h5
调整为 web
,开发者的 CI/CD
流程需要同步进行更新。Ways to reference third-party js:
manifest.json
file, fill in the html template path, and use the script method to import three-party js in the html template. The following example is part of the code of the html template with Baidu statistics added, and the template is all The code can refer to: custom template<!-- ... -->
<body>
<noscript>
<strong>Please enable JavaScript to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?xxxxxx";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
</body>
<!-- ... -->
The H5 version of uni-app
fully supports vue
syntax, so some writing methods may take effect on the H5 side, but not on the MiniApp or App side.
H5 has verified the stricter vue
grammar, and some irregularities will cause an alarm, for example: an object written after data
will cause an alarm, and function
must be written; the value of props
cannot be modified; the outermost part of the component Multiple nodes etc. are not allowed under the layer template
node.
What is generated after compiling to H5 version is a single page application (SPA).
If js cannot be connected to the Internet due to cross-domain, please note that network requests (request, uploadFile, downloadFile, etc.) have cross-domain restrictions in the browser. For solutions, see: https://ask.dcloud.net.cn/article /35267
The navigation bar and tabbar
of APP and MiniApp are native controls, and the coordinates of the element area do not include the native navigation bar and tabbar
; while the navigation bar and tabbar
in H5 are realized by div simulation, so the element coordinates Will include the height of the navbar and tabbar. In order to elegantly solve the multi-terminal height positioning problem, uni-app
adds 2 new css variables: --window-top
and --window-bottom
, which represent the distance between the top and bottom of the content area of the page distance. For example, if you want to float a menu above the native tabbar
, write bottom:0
before. After such writing is compiled into h5, this menu will overlap with tabbar
and be located at the bottom of the screen. Instead, use bottom:var(--window-bottom)
, no matter under the app or under h5, the menu will be suspended above the tabbar
. This avoids writing conditionally compiled code. Of course, you can still use H5's conditional compilation to deal with the difference in the interface.
Note that 100vh
includes the navigation bar when using the vh
unit in CSS. When using it, you need to subtract the height of the navigation bar and tabBar
. Some browsers also include the height of the browser action bar. Please pay attention when using it.
Normal support rpx
, px
is real physical pixel. It is not supported to use px as a dynamic unit by setting "transformPx": true
in manifest.json
.
Use the compass, geographic location, accelerometer and other related interfaces to use the https protocol, and the local preview (localhost) can use the http protocol.
When testing on the Chrome browser emulator device on the PC side, the location API needs to be connected to the Google server.
Page life cycles such as onLoad
, onShow
, etc. are not supported in components (except pages).
To avoid conflicts with built-in components, please add prefixes to custom components (but not u and uni). For example, the names of custom components that can be used: my-view
, m-input
, we-icon
, such as the names of custom components that cannot be used: u-view
, uni-input
, if already Some projects use names that may cause conflicts. Please modify the names. In addition, the names of custom components under WeChat MiniApp cannot start with wx.
vue3 开发阶段不会自动处理语法兼容问题,如果在低版本浏览器上运行,需要自行处理,可参考详情。
The browser kernels of various MiniApp are different, which may cause css compatibility issues. For more details, refer to: https://ask.dcloud.net.cn/article/1318
微信(可以使用virtualHost配置)/QQ/百度/抖音这四家小程序,自定义组件在渲染时会比App/H5端多一级节点,在写样式时需要注意:
flex
layout, directly setting the parent element of the custom component to display:flex
will not affect the root node inside the custom component, you need to set the current custom component to display:flex
.支付宝小程序默认启用了virtualHost配置不会插入节点,一般不存在如上问题。
The MiniApp tool prompts that vendor.js
is too large, and the conversion from es6 to es5 has been skipped. The conversion problem itself is ignored, because vendor.js
is already es5.
For volume control, refer to the following:
HBuilderX
, check Run-->Run to MiniApp Simulator-->Whether to compress the code at runtime
cli
can add the parameter --minimize
in package.json
, example: "dev:mp-weixin": "cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli- service uni-build --watch --minimize"
showLoading
is opaque, that is to say, the page content cannot be clicked when loading
is displayed.@
symbol is not allowed in file or folder names.dataType
, if it does not meet the specifications, an error will be thrown instead of being returned in the original format.canvas
component is identified by id
, not canvas-id
. It has not been processed yet, so it is necessary to actively add the id attribute.1rpx
, you need to use 1px
directly.scoped
is not supported.map
component is not correct on developer tool, but it is correct on mobile phone.windowHeight
obtained by getSystemInfo
is incorrect in the simulator, but the real device preview is correct.v-if
and v-for
cannot be used together under the same tag.template
tag in the outer layer of the rendered result, which will cause the styles corresponding to some selectors to not match.<se-video></se-video>
<se-...></se-...>
is a proprietary component of the 360 platform, which cannot be cross-platform, and requires conditional compilation of mp-360
pages configuration{
//...
"globalStyle": {
"mp-360": {
"navigationStyle": "custom" // 去掉uni-app header,使用360小程序header
}
}
//...
}
uni.login(OBJECT)
temporarily, use conditional compilation for the time being, refer to the document https://developer.huawei.com/consumer/cn/doc/development/quickApp-References/webview-api-hwaccountuni.login(OBJECT)
sign is placed in the root directory of the project, automatically copied to .quickapp/sign after compilation, and .quickapp will be deleted each time the compilation is completed to avoid loss of certificates