uniapp 开发规范(兼容性适配)

因 uniapp 需同时兼容PC端,移动端,微信小程序端,app端等,建议按以下开发规范开发,可更加有效避开多端不兼容的情况:

vue 文件使用 div标签包裹

html 复制代码
<template>
	<div>
	  <!-- 页面代码 -->
	</div>
</template>

容器样式不要写在组件上

此处 class 不要写在 u--form,单独用 view 包裹 u--form 来添加样式

html 复制代码
<view class="formBox">
			<u--form>

改组件样式使用样式穿透 + !important

直接在组件上添加样式,会出现某些端不生效的情况,建议统一用样式穿透 + !important实现

复制代码
	::v-deep .u-button--square {
		border-radius: 0 !important;
	}

文件上传需做 name 兼容处理

微信小程序上上传文件,无法获取到文件名,需做 name 兼容处理

js 复制代码
uploadOK(e) {
	if (e.file.name) {
		// 避免文件名中有逗号,导致云存储无法删除
		e.file.name = e.file.name.replace(/,/g, '')
	}
	this.fileList = [e.file]
},
js 复制代码
cloudPath: 'blog/' + timeMark + (this.fileList[0].name || Math.floor(Math.random() * 100)),
相关推荐
2501_9160088910 小时前
深入解析iOS应用启动性能优化策略与实践
android·ios·性能优化·小程序·uni-app·cocoa·iphone
巴巴博一20 小时前
uni-app 踩坑实录:实现“可拖拽全局悬浮按钮”时的 movable-view 坐标失效与 Flex 布局视错觉
vue.js·uni-app
阿奇__1 天前
h5微信授权code失效排查过程及解决记录
微信·uni-app
天籁晴空1 天前
微信小程序 静默登录 + 授权登录 双模式配合的设计方案
前端·微信小程序·uni-app
爱怪笑的小杰杰2 天前
uni-app Vue3 国际化最佳实践:告别应用重启,优雅实现多语言切换
前端·vue.js·uni-app
yqcoder2 天前
uni-app 数据缓存详解
缓存·uni-app
2501_915921432 天前
穿越HTTPS迷雾:Wireshark中的TLS抓包秘诀与文件合并方法
网络协议·ios·小程序·https·uni-app·wireshark·iphone
小徐_23332 天前
uni-app 组件库 Wot UI 2.0 发布了,我们带来了这些改变!
前端·微信小程序·uni-app
yqcoder2 天前
uni-app 之 页面路由
uni-app
小离a_a2 天前
uniapp小程序添加路由全局限制,增加路由白名单,登录后接口跳转参数正常传递
小程序·uni-app