<script>  
    type SystemInfoType =  {  
        windowWidth: number  
        windowHeight: number  
    }  
    export default {  
        data() {  
            return {  
                systemInfo: null as SystemInfoType | null  
            }  
        },  
        onLoad() {  
            const info = uni.getSystemInfoSync()  
            this.systemInfo = JSON.parse<SystemInfoType>(`{  
                windowWidth: ${info.windowWidth},  
                windowHeight: ${info.windowHeight}  
            }`)  
        }  
    }  
</script>还是有更简单的写法?
 
             
             
             
			 
                                        
                                     
            
4 个回复
爱豆豆 - 办法总比困难多
应该说是uts比较难
应该是没更简单的写法了
靐齉齾麤龖龗 - 解决不了问题,那就解决提出问题的人
ts就这样了,一堆的类型定义,uts还增加了许多类型
hikerw
多写ts就习惯了
hws007 - 我就是我!
choin
是可以这么写,但是官方让少用utsjsonobject,不知道为啥
2024-09-25 16:51
hws007
回复 choin: 因没明确对象下的类型,所以都要自定义类型,比较保险
2024-09-28 23:08