# unix-social **Repository Path**: ggbhack/unix-social ## Basic Information - **Project Name**: unix-social - **Description**: unix-社区交友项目 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 14 - **Forks**: 4 - **Created**: 2024-02-28 - **Last Updated**: 2025-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## uts vue3 setup语法糖 踩坑 目前写到P47 ### Q1 computed不支持 解决方案,使用 watchEffect ### Q2 箭头函数必须有大括号 在组件avatar中 ```uts // 编译报错 const load = () => tip.value = '' // 编译正常 const load = () => { tip.value = '' } ``` ### Q3 可选的设置 e.target?.setAttribute("src", "/static/default-avatar.png") ### Q4 Object as PropType < TopicModel > 编译器爆红,页面类型无法判断 等待官方修复,或者使用 options-api ### Q5 page.value === 1 类型判断超级严谨 == === ```uts const page = ref(1) // 报警告 warning: Identity equality for arguments of types Number and Int can be unstable because of implicit boxing​ if(page.value === 1){ } ``` ### Q6 onLoad 必须有参数 没有的话会报错 ```uts onLoad((_:OnLoadOptions)=> { loadCategories() }) ``` ### Q7 函数顺序 bug影响有点大 如果顺序在后面,就会找不到对应的函数 因此onLoad方法一定得放在最后 ### Q8 ref的使用 目前写到P58 ### Q9 外界导入的普通方法和箭头函数使用时需要注意📢 ```uts // 用户登出 export const logout=()=>{ uni.clearStorage() // // 更新本地用户状态 updateUserState(null) loginState.value = false } export function logout{ uni.clearStorage() // // 更新本地用户状态 updateUserState(null) loginState.value = false } ``` ### Q10 setStorageSync 对应的值不能为null ```uts // 这会导致编译报错 uni.setStorageSync('user_token',null) ``` ### Q11 如何将本都缓存获取并设置为我们需要的类型 getStorageSync ```uts /** * 初始化用户信息 */ export const initUserStore = ()=>{ const userInfo = uni.getStorageSync('user_info') if(userInfo!=null){ loginState.value = true const user = JSON.parse(JSON.stringify(userInfo)) updateUserState(user) // updateUserState(userInfo as UserModel) // updateUserState(uni.getStorageSync('user_info') as Object as UserModel) // console.log(uni.getStorageSync('user_info')) // const userInfoMap = userInfoObject!!.toMap() // console.log(userInfoMap) // let mapObj = new Map() // mapObj.put("name","zhangsan") // mapObj.put("age",12) // console.log(mapObj) // userInfoMap.forEach(function(value:any,key:string){ // console.log(key) // console.log(value) // }) // userInfoObject?.toMap()?.forEach((v:any) => { // // console.log(v) // }) } } ``` ### Q12 App.nuve 不能使用setup语法糖 ```uts ``` 目前写到P84 ### Q13 类型判断错误 boolean|underfine 无法给到boolean ```uts // user-safe.nvue onPageShow(()=>{ phone.value = userState.value?.phone??'' // if(userState.value == null) return // password.value = userState.value?.password || false password.value = userState.value?.password?? false }) ``` ### Q14 uts中没有onShow ```uts // my.nvue onPageShow(()=>{ console.log('-----------onPageShow------') }) ``` ### Q15 官方demo参考 [uts demo](https://gitcode.net/dcloud/hello-uni-app-x/-/tree/alpha) ### Q16 调用子组件方法 ```uts // index const longPageRef = ref([]) (longPageRef.value as ComponentPublicInstance[])[tabIndex.value].$callMethod('refreshData', ()=>{ uni.stopPullDownRefresh(); }) ``` 目前写到P106 ### 17 ctrl + k 格式化要注意 参考代码组件 upload-image ### 18 定义带类型的 emits ```javascript const emits = defineEmits<{ (event: 'reply', obj: ReplyEmit): void }>() ``` ### 19 分享组件 share/share ### 20 follow-button.uvue v-show的坑 ```vue ``` ### 21 display:none 报错 ```html 话题标题 .navbar-title { display: none; } ``` ### 22 请求返回为data:[] 如果定义的类型不对,也会报错 看该接口 /support/ding