uniapp开发注意事项

1、picker省市区选择器
picker当mode = region时为省市区选择器,在App和H5平台数据为空,需要自行填充数据,本次使用的DCloud插件
2、canvas在app端为白屏时
是因为图片过大,需要缩小图片大小

let that = this
uni.getImageInfo({
	src: path,
	success: function(res) {
		uni.showLoading({
			title: '上传中.'
		});

		var width = res.width / 10,
			height = res.height / 10;
		that.w = width;
		that.h = height;
		//获取当前时间
		let roleNameInfo = date.formatHMS()
		let location = that.addr
		//创建canvas
		const ctx = uni.createCanvasContext('firstCanvas', that);
		ctx.drawImage(res.path, 0, 0, width, height); //先画出图片
		ctx.setFontSize(12) //注意:设置文字大小必须放在填充文字之前,否则不生效
		ctx.font = 'nomal 12px 微软雅黑'
		ctx.setFillStyle('white');
		ctx.strokeText(roleNameInfo, 6, height - 4);
		ctx.strokeText(location, 6, height - 20);
		ctx.fillText(roleNameInfo, 6, height - 4);
		ctx.fillText(location, 6, height - 20);
		let name = that.imgData.name + "照片";
		ctx.strokeText(name, 6, 20);
		ctx.fillText(name, 6, 20);
		ctx.draw(false, () => { //开始制作
			setTimeout(() => { //使用定时是因为制作水印需要时间,设置定时才不会出bug
				uni.canvasToTempFilePath({ //将画布中内容转成图片,即水印与图片合成
					width: width, // 截取的画布的宽
					height: height,
					canvasId: 'firstCanvas',
					success: (v) => {
						uni.hideLoading();
						console.log(v)
					},
					fail: (error) => {
						uni.hideLoading();
					console.log(error)
					}
				}, that)
			}, 200)
		})
		
		//end
	},
		})

3、uniapp使用color ui时,app端复选框样式问题,在App.vue的style中加入

uni-checkbox .uni-checkbox-input {
	border-radius: 50% !important;
	color: #ffffff !important;
}

uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
	color: #fff;
	border-color: rgb(0, 122, 255);
	background: rgb(0, 122, 255);
}
uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:after {
	font-size: 18px;
}

app端input视图不更新

这个很坑,加个定时器加好了,我也不知道为什么
<template>
	<view>
		<input type="text" placeholder="请输入" v-model="weight" @input="numRule">
	</view>	
</template>

<script>
	export default {
		name:"home",
		data(){
			 return {
			 	weight:""
			 }
		},
		methods:{
			numRule(e){
			let num = e.detail.value
				num = num.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符  
				num = num.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的  
				num = num.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
				num = num.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数  
				if (num.indexOf(".") < 0 && num != "") { //以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额 
					num = parseFloat(num);
				}
				setTimeout(() => {
					this.weight = num
				}, 0)
				
			}
	   }
	}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值