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}`">
相关推荐
河北清兮网络科技7 小时前
短剧 APP 产品说明
小程序·uni-app·短剧
宠友信息12 小时前
一套基于uniapp+springboot完整社区系统是如何实现的?友猫社区源码级功能解析
java·spring boot·后端·微服务·微信·uni-app
碎像21 小时前
掌握uniapp发布微信小程序、App(Android)
微信小程序·小程序·uni-app
stpzhf21 小时前
uniapp nvue组件多个text在一行并且高亮其中一些文字
前端·javascript·uni-app
qq_3168377521 小时前
制作uniapp原生插件 在本地离线打包中测试 集成在云打包中
uni-app
程序媛徐师姐21 小时前
Java基于SSM的实验室管理微信小程序,附源码+文档说明
java·微信小程序·实验室管理·实验室管理微信小程序·java实验室管理微信小程序·java实验室管理小程序·实验室管理小程序
Fate_I_C2 天前
uniappx 鸿蒙运行包制作失败
华为·uni-app·uniapp·harmonyos
chQHk57BN2 天前
跨平台前端开发:用Flutter和UniApp一次编写多端运行
flutter·uni-app
自然 醒2 天前
uni-app开发微信小程序,如何使用towxml去渲染md格式和html标签格式的内容?
微信小程序·uni-app·html
CHB2 天前
uni-agent,你的数字员工来了
人工智能·uni-app·vibecoding