标签的改动
- div 改成 view
- span、font 改成 text
- a 改成 navigator
- img 改成 image
- input 还在,但type属性改成了confirmtype
- form、button、checkbox、radio、label、textarea、canvas、video这些还在。
- select 改成 picker
- iframe 改成 web-view
- ul、li没有了,都用view替代
audio 不再推荐使用。音频api文档 https://uniapp.dcloud.io/component/audio.html
路由配置、跳转
uni的路由全部是在pages.json中配置的
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages{"path": "pages/home/index", //文件目录地址"style": {"navigationBarTitleText": "首页"}}....
uni.navigateTo({ //路由跳转url: '/pages/home/index'});
关于适配
蓝湖切到web平台 宽度375
-
下拉刷新、上拉加载
配置enablePullDownRefresh、onReachBottomDistance
- 官网 https://uniapp.dcloud.io/tutorial/page.html#lifecycle
- 同时pages.json中对应路由里也可以配置触发距离
然后在页面methods中定义这两个方法即可{"path": "pages/messageNotification/index","style": {"navigationBarTitleText": "消息通知","enablePullDownRefresh": true,//开启下拉刷新"onReachBottomDistance": 150 //距离}},
onPullDownRefresh(){console.log('下拉刷新')uni.stopPullDownRefresh() //数据处理完成后记得关闭loading},onReachBottom() {console.log('上拉加载')},
动态修改页面title
uni.setNavigationBarTitle({title: 'xx'});
关于兼容微信小程序 :style 使用变量问题
加上[ ]就行:style="cellStyle" //无效:style="[cellStyle]"
关于子组件onLoad不触发
onLoad改成mountedglobalData、iphonex及以上机型
在app.vue文件中定义
获取globalData: {isIPhoneX: false //是否为iphonex及以上机型},onLaunch: function() {console.log('App Launch')let _this = this;uni.getSystemInfo({success: res => {// console.log('res',res)if (res.safeArea.top > 20) { //x及以上的异形屏top为44,非异形屏为20_this.globalData.isIPhoneX = true}},fail(err) {console.error(err);}})}
getApp().globalData
跨域处理
manifest.json找到h5"h5" : {"devServer" : {"disableHostCheck" : true,"proxy" : {"/lsm-service" : {"target" : "http://...","secure" : false,"changeOrigin" : true},"/lsm-yhzx" : {"target" : "http://...","secure" : false,"changeOrigin" : true}}}},
