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}`">
相关推荐
wordbaby1 天前
从双端内卷到一库多端:基于 pnpm + Taro 4 + RNOH 鸿蒙的 Monorepo 跨端架构实战
前端·微信小程序·app
PedroQue991 天前
Vue Router 4.x风格导航守卫全面升级
前端·uni-app
Haibakeji1 天前
APP小程序定制开发项目频繁延期?前期规避方法与落地避坑指南
小程序·uni-app·软件需求
anyup1 天前
迁移uni-app x,我是如何让 AI 把我一步步搞崩溃的...
前端·uni-app·trae
2501_916007471 天前
申请 iOS 推送证书并配置 APNs 群发推送教程
android·ios·小程序·https·uni-app·iphone·webview
博客zhu虎康1 天前
uni-app云打包显示编译成功,但是一直没有进入打包队列,后面也一直没反应
uni-app
JavaDog程序狗2 天前
【指南】uni-app微信小程序多环境CI-CD完全指南
ci/cd·uni-app·jenkins
PedroQue992 天前
uni-router v2.1.0 升级:导航守卫全面支持返回值模式
前端·uni-app
码云之上3 天前
小程序 iOS 多输入框焦点乱序脱坑记
ios·微信小程序·taro
2501_915909063 天前
iOS test 测试怎么做?功能、性能、兼容、稳定与安全五类测试指南
android·ios·小程序·https·uni-app·iphone·webview