uniapp常用功能

1.兼容各端的固定定位

<view class="iconfont icon-chuangzuo edit"></view>

.edit{
			width: 80rpx;
			height: 80rpx;
			background-color: #0199FE;
			border-radius: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			color: #ffffff;
			font-size: 36rpx;
			position: fixed;
			bottom: calc(10px + var(--window-bottom));
			right: calc(10px + var(--window-right));
			z-index: 999;
		}

2.上传图片

//添加图像
clickInsertImage() {
	uni.chooseImage({
		success: async res => {

			uni.showLoading({
				title: "上传中请稍后",
				mask: true
			})
			for (let item of res.tempFiles) {
				let suffix = item.path.substring(item.path.lastIndexOf("."));
				let randomName = Date.now() + "" + String(Math.random()).substr(3, 6) + suffix

				let res = await uniCloud.uploadFile({
					filePath: item.path,
					cloudPath: item.name || randomName
				})
				this.editorCtx.insertImage({
					src: res.fileID
				})
			}
			uni.hideLoading()
		}
	})
},

3.高德地图web服务(IP定位):https://lbs.amap.com/api/webservice/summary 

//获取所在省市
function getIp(){
	return new Promise((resolve,reject)=>{
		uni.request({
			url:"https://restapi.amap.com/v3/ip?key=4a43fb1fc001e386a52215b6feea63f4",
			success:res=>{				
				let str=""				
				typeof(res.data.province) == "string" ? str=res.data.province :str="火星"
				resolve(str)
				let obj={
					province:str,
					time:Date.now()
				}
				uni.setStorageSync("historyProvince",obj);				
			},
			fail:err=>{
				reject(err)
			}
		})
	})	
}

4.查询数据库
        用jql

getData() {
	let artice = db.collection("artice").getTemp()
	let user = db.collection("uni-id-users").field('_id, username, nickname, avatar_file').getTemp()
	
	db.collection(artice, user).get().then(res => {
		this.list = res.result.data
		console.log(this.list);
	})
},

         用前端组件

<unicloud-db v-slot:default="{data, loading, error, options}" collection="article, uni-id-users"
field="_id,publish_date,title,description,picurls, user_id{_id,nickname,avatar_file}">
	<view v-if="error">{{error.message}}</view>
	<view v-else>
		<view class="item" v-for="(item, index) in data" :key="index">
			<blog-item :item="item"></blog-item>
		</view>
	</view>
</unicloud-db>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值