艾璞
艾璞
  • 发布:2024-04-15 13:21
  • 更新:2024-04-15 13:43
  • 阅读:74

script lang="uts" setup 中在android中无法使用defineProps

分类:uni-app x

android是不支持 lang="uts" setup 吗

2024-04-15 13:21 负责人:无 分享
已邀请:
DCloud_UNI_FengXY

DCloud_UNI_FengXY

可以贴一下代码和HBuilderX版本号

  • 艾璞 (作者)

    代码 Hbuildx版本号:4.12.2024041009-alpha

    代码我贴下面了

    2024-04-15 13:29

艾璞

艾璞 (作者)

代码 Hbuildx版本号:4.12.2024041009-alpha

<template>  
    <view class="ch_row" :style="getRowStyle()">  
        <slot></slot>  
    </view>  
</template>  
<script lang="uts" setup>  
    const props = defineProps({  
        gutter: {  
            type: [String, Number],  
            default: () => 0  
        }  
    })  

    const getRowStyle = () => {  
        return new Map<string, string>([['padding', `${props.gutter}px 0 0 ${props.gutter}px`]])  
    }  

    provide('row_gutter', props.gutter);  
</script>  
<style>  
    .ch_row {  
        display: flex;  
        flex-direction: row;  
        flex-wrap: wrap;  
    }  
</style>
DCloud_UNI_FengXY

DCloud_UNI_FengXY

注意根据报错修改代码,有两处错误,都是缺少返回类型

<script lang="uts" setup>  
    const props = defineProps({  
        gutter: {  
            type: [String, Number],  
            default: () : number => 0  
        }  
    })  

    const getRowStyle = () : Map<string, string> => {  
        return new Map<string, string>([['padding', `${props.gutter}px 0 0 ${props.gutter}px`]])  
    }  

    provide('row_gutter', props.gutter);  
</script>
  • 艾璞 (作者)

    这个我改过不是这个的问题哦 还是会报错error: The integer literal does not conform to the expected type Unit‌

    2024-04-15 13:48

  • 艾璞 (作者)

    删除掉defineProps的代码就又正常了

    2024-04-15 13:49

  • DCloud_UNI_FengXY

    回复 艾璞: 注意看我给的代码,有两处要调整,default和getRowStyle都要配置返回类型,我测试没有问题

    2024-04-15 15:21

  • 艾璞 (作者)

    回复 DCloud_UNI_FengXY: 谢谢是这个问题实在感谢了

    2024-04-15 16:29

要回复问题请先登录注册