uni-app实操大全

登录时判定用户登录状态,若已登录则跳过登录页

核心思路:
1.在应用生命周期onLaunch判断用户登录信息是否存在
2.若存在用户登录信息,则跳转到首页,关闭应用启动页
    若不存在用户登录信息,则进入到登录页,关闭应用启动页

实现文件2-1App.vue

onLaunch: function() {
			console.log('App Launch')
			// #ifdef APP-PLUS  
				var userIdStr = uni.getStorageSync('userIdStr');
				if(!userIdStr){
					//不存在用户信息
					//则关闭启动页,直接进到登录页
					console.log('不存在用户信息')
					plus.navigator.closeSplashscreen();
				}else{
					//存在用户信息
					//则转入主页,且页面跳转完成后再关闭启动页
					console.log('存在用户信息')
					uni.reLaunch({
						url:'./pages/index/index',
						success:()=>{
							//页面跳转完成后再关闭启动页
							plus.navigator.closeSplashscreen();
						}
					})
				    
				}
				// #endif
		}

实现文件2-2manifest.json
这里主要是将splashscreenalwaysShowBeforeRenderautoclose设为false,默认均为true

"app-plus" : {
        "usingComponents" : true,
        "nvueStyleCompiler" : "uni-app",
        "compilerVersion" : 3,
        "splashscreen" : {
            "alwaysShowBeforeRender" : false,
            "waiting" : true,
            "autoclose" : false,
            "delay" : 0
        },

拨打电话

//拨打电话
	call(phoneNum){
		uni.makePhoneCall({
		 	// 手机号 
             phoneNumber: phoneNum, 
			// 成功回调
			success: (res) => {
			console.log('调用成功!')	
			},
			// 失败回调
			fail: (res) => {
				console.log('调用失败!')
			}})
	}

禁止页面滑动

局部配置

"path": "pages/user/login",
"style": {
		"app-plus": {  
			  "titleNView": false,
			  "bounce": "none"//禁止滚动
		},
		"navigationBarTextStyle": "white"	
}

全局配置

"globalStyle": {
	"app-plus": {
		"bounce": "none"//禁止滚动
	 }
 },

uni-app发送request请求后端接受不到参数

解决方法如下:
在请求头header中添加:
'Content-type':'application/x-www-form-urlencoded'

'content-type': 'application/x-www-form-urlencoded;charset=utf-8'

赞赏