uniapp:微信小程序图片上传,选择图片转base64

<image :src="$imgUrl+alipay_image" mode="">image>

微信小程序:全局定义的变量$imgUrl,页面中会报undefined,需要在data中重新引入

data() {
	return {
		$imgUrl:this.$imgUrl,
		alipay_image: '',
	}
},
uni.chooseImage({
	count: 1,
	sizeType: ['original', 'compressed'],
	success: (res) => {
		uni.getFileSystemManager().readFile({
			filePath: res.tempFilePaths[0],
			encoding: 'base64',
			success: res => {
				let base64 = 'data:image/png;base64,' + res.data;
				this.$http.post("Users/base64_upload", {
					image: base64
				}).then(res => {
					if (res.code == 200) {
						this.alipay_image = res.data;
					}
				})
			}
		})
	}
});

你可能感兴趣的:(微信,微信小程序,小程序)