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}`">
相关推荐
andr_gale1 天前
02_uniapp自定义上凸效果的底部TabBar
前端·javascript·uni-app·移动端
拖孩1 天前
用 AI 重解千年观音灵签,做了一个微信小程序,每天摇一摇,命运给你回应
前端·后端·微信小程序
不爱说话郭德纲1 天前
uni-app x iOS 扫码模糊怎么办?AVFoundation 灰尘级别摄像头助你超广角聚焦
前端·uni-app·app
java1234_小锋1 天前
【免费】微信小程序网约车(打车,在线叫车,移动出行)系统(SpringBoot4+Vue3) 锋哥原创出品,必属精品
微信小程序·网约车·在线叫车·移动出行
CHB2 天前
uni-app x 蒸汽模式 性能测试基准报告 Benchmark【Android版】
android·ios·uni-app
AI砖家2 天前
AI编程—微信小程序开发规范
微信小程序·小程序·notepad++·ai编程
sam-zy3 天前
微信小程序+ESP8266+Arduino 开发智能插座,有本地OTA功能
微信小程序·小程序
A24207349303 天前
微信小程序开发:常用基础语法与指令详解
微信小程序·小程序·notepad++
游戏开发爱好者84 天前
系统状态:专为iPhone和iPad设计的实时系统性能监控工具全面介绍
android·ios·小程序·uni-app·iphone·webview·ipad
2501_915909064 天前
全面解析iOS应用上架到App Store的完整流程与关键注意事项
android·macos·ios·小程序·uni-app·cocoa·iphone