天天看点

uniapp简单聊兼容

直接上代码

uniapp的代码需要明确的指出兼容性

比如我想在H5,APP,weixin做跨平台兼容

建议使用原生,越接近原生的uniapp的组件api插件等等不太会出现问题

但是也存在缺点由于环境的不一样

比如H5你可以大胆的写js的东西,使用vue,vuex,vue-router等等一些属于vue的东西,不需要考虑兼容问题。

H5与原生有冲突,与安卓APP很难融合,但却与微信小程序差异不大,因为学过小程序都知道,

小程序的视图层,逻辑层,组件,引用,模块,

module,exports,template,组件关系与vue很相似

也支持es6转es5.

如果你需要在安卓或者ios上面适配

建议写两份代码,更好维护一些

没必要一边注意APP一边注意H5

如下的代码

一个功能三个兼容难免维护起来麻烦很多

uni.getStorage({
			key:"remark",
			success:function(res){
				uni.request({
					url:"https://25q686n876.qicp.vip/tp5/publica/index/Bii/Look",
					method:"POST",
					header:{
						"Content-Type":"application/x-www-form-urlencoded"
					},
					data:{user:res.data.user,time:res.data.time},
					dataType:"json",
					success:function(res){
						vue.list=res.data.info
					}
				})
			}
		})
由于我写的是uniapp原生代码举例子其实只要写上面一段就可以运行了
突出能用原生uniapp组件api解决的问题 一律不要考虑什么vuex,vue-router等等之类的H5的东西,免得麻烦。
// #ifdef H5
		uni.getStorage({
			key:"remark",
			success:function(res){
				uni.request({
					url:"https://25q686n876.qicp.vip/tp5/publica/index/Bii/Look",
					method:"POST",
					header:{
						"Content-Type":"application/x-www-form-urlencoded"
					},
					data:{user:res.data.user,time:res.data.time},
					dataType:"json",
					success:function(res){
						vue.list=res.data.info
					}
				})
			}
		})
		// #endif
		//#ifdef MP-WEIXIN
		uni.getStorage({
			key:"remark",
			success:function(res){
				uni.request({
					url:"https://25q686n876.qicp.vip/tp5/publica/index/Bii/Look",
					method:"POST",
					header:{
						"Content-Type":"application/x-www-form-urlencoded"
					},
					data:{user:res.data.user,time:res.data.time},
					dataType:"json",
					success:function(res){
						vue.list=res.data.info
					}
				})
			}
		})
		//#endif
		// #ifdef APP-PLUS
		uni.request({
			url:"https://25q686n876.qicp.vip/tp5/publica/index/Bii/Look",
			method:"POST",
			header:{
				"Content-Type":"application/x-www-form-urlencoded"
			},
			data:{user:options.user,time:options.time},
			dataType:"json",
			success:function(res){
				vue.list=res.data.info
			}
		})
		// #endif
           

继续阅读