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}`">
相关推荐
CHB20 小时前
HDC2026 演讲实录|AI 驱动的跨端进化:利用 uni-agent 快速构建高性能鸿蒙应用
uni-app·harmonyos
2501_915918411 天前
iOS App性能测试工具的实现方法与优化循环指南
android·ios·小程序·https·uni-app·iphone·webview
玩烂小程序1 天前
微信小程序手串DIY功能开发实录:飞入动画 + 环形排布 + 拖拽换序 + 旋转查看 + 保存设计
微信小程序
斯内普吖1 天前
(开源)高校素拓分管理系统小程序实战指南 基于 Java + SpringBoot + uni-app + Vue + MySQL
java·spring boot·mysql·小程序·uni-app·开源
何时梦醒1 天前
HTML5 Canvas 从入门到实战:手把手教你打造一款"打飞机"小游戏
微信小程序
海阔天空66881 天前
uniapp开启调试模式
uni-app·uniapp开启调试模式
master3361 天前
SSL 证书链问题导致微信小程序无法正常工作
网络协议·微信小程序·ssl
anyup2 天前
分享 5 套 uni-app 实用主题,一键适配暗黑模式
前端·uni-app·视觉设计
gg159357284602 天前
Uni-app跨平台开发全解课程:从零基础到企业级多端落地实战
vue.js·uni-app
wuxia21182 天前
在5种环境中编写点击元素改变内容和颜色的JavaScript程序
javascript·微信小程序·vue·jquery·react