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)),
相关推荐
不法14 小时前
uniapp map地图导航/地图路线
前端·vue.js·uni-app
淡淡的幼稚2 天前
【YFIOs】从传感芯片到表格曲线
uni-app·.net
宠友信息2 天前
多端即时通讯源码技术实践,Redis路由、MySQL持久化与Socket接入
spring boot·websocket·mysql·uni-app
宠友信息2 天前
Spring Boot与异步审核构建仿小红书源码内容发布全流程
java·数据库·spring boot·redis·mysql·oracle·uni-app
蜡台2 天前
uniapp vue2 转 vue3
前端·javascript·uni-app·vue3·vue2
2501_916008892 天前
iOS 证书管理最佳实践 从创建到续期的完整指南
android·ios·小程序·https·uni-app·iphone·webview
敖行客 Allthinker3 天前
UniApp iOS APNs 推送证书一站式配置
uni-app·mac
梦曦i3 天前
uni-router新推useUniEventChannel,彻底解决页面通信难题
前端·uni-app
宠友信息3 天前
内容社区源码多端数据协议与 Spring Boot 状态流转实现思路
java·spring boot·websocket·uni-app
2501_916007473 天前
iPad 怎么抓包 从代理模式到暴力抓包的操作方法
android·ios·小程序·uni-app·代理模式·iphone·ipad