当前位置:网站首页>Uni app essay

Uni app essay

2022-06-13 08:44:00 Dependency_ Lai

Get user rights

 Insert picture description here

 //  Get user information 
uni.getUserProfile({
    
	desc: ' Sign in ',     //  This parameter is required 
	lang: 'zh_CN',  //  Return Chinese information 
	success: (infoRes) => {
    
		console.log(infoRes.userInfo)
	},
	fail: (error) => {
    
		console.log(error)
	}
})

infoRes.userInfo Parameters :
 Insert picture description here

Page Jump

1、navigateTo, Keep the current page , The page will display by default after jump ‘ return ’ Button , Click to return to the current page

Be careful :url Limited length , Too long will cause parameter transfer failure , You can use encodeURIComponent How to solve .
encodeURIComponent(JSON.stringify(data))

// With no arguments 
uni.navigateTo({
    url:"../../pages-merchants/pages/home/Home"})
// With parameters 
uni.navigateTo({
    url:"../../pages-merchants/pages/home/Home?index=1 && data=" + encodeURIComponent(JSON.stringify(data))})
// Receiving parameters 
onLoad: function (option) {
     //option by object type , Will serialize the parameters passed from the previous page 
   console.log(option.index); // Print out the parameters passed from the previous page .
   console.log(JSON.parse(decodeURIComponent(option.data)); // Print out the parameters passed from the previous page .
}

2、 Tag jump , The method of parameter transmission is the same as above

<navigator url="/pages/index/Index" open-type="navigate">
     <view> Point me to jump </view>
</navigator>

3、reLaunch, Close current page , The page will display by default after jump ‘ home page ’ Button , Click to return to the home page

uni.reLaunch({
    url:"../../pages-merchants/pages/home/Home"})

Add... To the new page hideHomeButton The home button can be hidden

onShow() {
    
			uni.hideHomeButton({
    
				success: function() {
    
					console.log(' Hide Home Button  ')
				}
			})
		}

4、switchTab, Close all other non tabBar page , Jump to tabBar page ,

uni.switchTab({
    
    url: '/pages/index/Index'
});

5、redirectTo, Close current page , The page will display by default after jump ‘ return ’ Button , Click to return to the previous page

uni.redirectTo({
    
    url: '/pages/index/Index'
});

6、navigateBack, Close current page , Go back to the previous page or multi-level page

uni.navigateBack({
    
    delta: 1 // Number of pages returned 
});

Dynamically set the page title

onLoad(options) {
    
	uni.setNavigationBarTitle({
    
		title: options.id ? ' Add receiving address ' : ' Edit shipping address '
	});
},

image label

image label Default width 300px,height225px, Set up mode You can customize the cropping or scaling mode , Prevent the picture from stretching and deforming
 Insert picture description here

Call the mobile phone to make a call

uni.makePhoneCall({
    
		phoneNumber: phone, //  cell-phone number 
		//  Successful callback 
		success: (res) => {
    
			console.log(' Successful call !')
		},
		//  Failed callback 
		fail: (res) => {
    
			console.log(' Call failed !')
			this.call_phone();// Repeat the call 
		}

Call wechat map

1、 Check the location

uni.openLocation({
    
	latitude: data.latitude,  //  dimension , -90 ~ 90
	longitude: data.longitude //  longitude , -180 ~ 180
});

2、 Select location

uni.chooseLocation({
    
	// The default open location 
	latitude: data.latitude,
	longitude: data.longitude,
	success: function (res) {
    
		console.log(res)
	}
});

 Insert picture description here
3、 Get current location

uni.getLocation({
    
	type: 'wgs84',
	success: function (res) {
    
		console.log(res)
	}
});

 Insert picture description here

storage cache

// Store user information in the cache 
uni.setStorage({
    
	key: 'userInfo',
	data: infoRes.userInfo,
	success: function () {
    
			// Authorized success , Go to other pages 
			uni.navigateTo({
    
				url:"../../pages-merchants/pages/home/Home"
			})
	}
});
// Use user information 
uni.getStorage({
    
	key: 'userInfo',
	success: (res) => {
    
		this.userInfo = res.data;
	}
});

Prompt box

uni.showToast({
    
	title:" Successful release " 
})
uni.showModal({
    
	title: ' Tips ',
	content: ' Confirm to delete the product ?',
	confirmColor: '#2979ff',
	cancelText: " Cancel ", //  Cancel button text  
	confirmText: " confirm ", //  Confirm button text  
	showCancel: true, //  Whether to display the Cancel button , The default is  true
	confirmColor: '#f55850',
	cancelColor: '#39B54A',
	success: (res) => {
    
		if (res.confirm) {
    
		
		}else{
    
			
		}
	}
});
原网站

版权声明
本文为[Dependency_ Lai]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270538335007.html