8***@qq.com
8***@qq.com
  • 发布:2021-10-31 23:16
  • 更新:2021-10-31 23:16
  • 阅读:314

typescript模板组件报错

分类:uni-app

报错
Property 'height' does not exist on type '{ cheight(): any; }'. Did you mean 'cheight'?

怎么才能不用 this as any 来使用
以下是整页代码

<template>  
    <view>  
        <view :dd="cheight" @click="dds">  
            测试1  
        </view>  
    </view>  
</template>  

<script lang="ts">  
    export default {  
        name:"ceshi1",  
        props:{  
            height: {  
                type: [Number, String],  
                default: 251  
            },  
        },  
        data() {  
            return {  

            };  
        },  
        computed:{  
            cheight(){  
                return this.height  
            }  
        },  
        methods:{  
            cheight(){  
                //报错  
                //Property 'height' does not exist on type '{ cheight(): any; }'. Did you mean 'cheight'?  
                return this.height  
            },  
            dds(){  
                //不报错  
                return (this as any).height  
            }  
        }  
    }  
</script>  

<style>  

</style>  
2021-10-31 23:16 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复