uniapp - 微信小程序

一、background-image 大图不显示的问题

解决方法:

1、使用网络地址;2、使用 base64

复制代码
urlTobase64(filePath) {
		// #ifdef MP-WEIXIN
		let img = `${filePath}`,
			imgBase64 = wx.getFileSystemManager().readFileSync(img, "base64"),
			base64Url = `data:image/png;base64,${imgBase64}`;
		console.log("data:image/png;base64", "图片转换成功");
		return base64Url
		// #endif
},

<!-- #ifdef MP-WEIXIN -->
<view class="inner-box" :style="{backgroundImage:`url(${$utils.urlTobase64('/static/image/top.png')})`}">
<!-- #endif -->
	<!-- #ifdef APP -->
	<view class="inner-box">
	<!-- #endif -->
	</view>

.inner-box {
		background-image: url('/static/image/top.png');
	}

二、uni. emit() uni.on() 不生效

解决方法:

放到 onReady() 方法里 ,onLoad() 方法 监听不到

三、高德定位

解决方法:

高德微信小程序SDK amap-wx.130.js下载地址

复制代码
import amapWX from '../utils/amap-wx.130.js'
let utils = {
	getAmapWXLocation() {
		// #ifdef MP-WEIXIN
		return new Promise((resolve, reject) => {
			const amapPlugin = new amapWX.AMapWX({
				key: '9a000f67903479b1f49cc05c59057108'
			});
			amapPlugin.getRegeo({
				success: (res) => {
					let data = res[0]
					console.log('定位成功', data)
					let position = {
						longitude: data.longitude,
						latitude: data.latitude,
						address: data.regeocodeData.formatted_address,
					}
					console.log('position: ', position);
					resolve(position)
				},
				fail(err) {
					reject(err)
					console.log('定位失败', err)
				}
			});
		})
		// #endif
	}
}
export default utils;

调用

复制代码
getLocationInfo() {
	// #ifdef MP-WEIXIN
	this.$utils.getAmapWXLocation().then(loc => {
		this.sLatitude = loc.latitude;
		this.sLongitude = loc.longitude;
		this.sLocation = loc.address;
		console.log('loc: ', loc);
	})
	// #endif
}

四、image 无法加载

分析问题所在:/pages/template/undefined/,路径有问题;

因为 $imgBaseUrl 这个路径 是写在 main.js 里边的

复制代码
 <image :src="`${$imgBaseUrl}${img}`">

解决方法

复制代码
export default {
		data() {
			return {
				imgBaseUrl: this.$imgBaseUrl,
			}
		}
}


 <image :src="`${imgBaseUrl}`">
相关推荐
PedroQue993 小时前
V1.6.1性能优化:高频路径提速与代码精简
前端·uni-app
skiyee21 小时前
🔥UniApp 仅需 5 行代码!实现所有页面中控制应用主题变化
前端·微信小程序
夏碧笔2 天前
uni-app跨端地图实战:用第三方LBS替代微信平台收费服务
uni-app
Jinkey2 天前
要用户手机号真的是为了打骚扰电话吗?浅谈微信生态会员账号体系与资产合并
后端·微信·微信小程序
用户4324281061144 天前
微信小程序从0到1接入微信支付的完整攻略
微信小程序
spmcor6 天前
微信小程序 setStorageSync 踩坑实录:别让"顺手一存"变成"隐形炸弹"
微信小程序
用户4324281061146 天前
小程序埋点设计规范:如何设计可扩展的数据采集体系
微信小程序
用户6990304848757 天前
try catch使用场景 处理同步代码错误兼容用的
javascript·uni-app
ITKEY_7 天前
uniapp微信开发者工具 更改AppID失败 touristappid
uni-app
Geek_Vison7 天前
APP瘦身实战:从80MB+砍到15MB——基于小程序容器技术剥离APP非核心业务的实践分享
小程序·uni-app·mpaas