vue3开发uniapp转字节小程序注意事项
开发相关地址
1.抖音开放平台 2.开发者平台
项目本身是vue3+ts+uniapp写的微信小程序,因产品需求要转换成抖音小程序
1.provide-inject 跨层通信不支持问题
uniapp转的抖音小程序,在使用隔代注入时,因为底层生命周期问题没办法在setup声明周期中拿到inject的数据,后写了demo问了抖音技术客服,说是uniapp自身问题。。。没提供解决方案
https://github.com/dcloudio/uni-app/issues/3360#issuecomment-1074913528
目前解决方案:1.使用store去平替,但要注意响应式数据相关业务
2.使用正常传参方式(不推荐)
3.使用eventsBus (不推荐)
2.不能自定义头部,需要去申请
3.不能使用moment 日期插件
使用moment
包会导致编译预览时无法预览
解决方案
utils/index.ts
/**
* 处理时间格式
* @param format 格式 eg:yyyy-MM-dd HH:mm:ss
* @param date 时间对象|字符串
*/
export const formatTime = (
format = 'yyyy-MM-dd HH:mm:ss',
date: Date | string = new Date(),
padZero = true,
): string => {
if (typeof date === 'string') date = new Date(date)
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
const formatMap: {
[key: string]: any } = {
yyyy: year.toString(),
MM: padZero ? month