r***@hotmail.com
r***@hotmail.com
  • 发布:2021-06-08 17:16
  • 更新:2021-06-08 17:55
  • 阅读:847

【不是Bug】使用TS + vue-property-decorator 编译H5正常,APP真机调试出现无法读取属性问题

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: Mac OS Big Sur 11.0.1

手机系统: iOS

手机系统版本号: IOS 14

手机厂商: 苹果

手机机型: iPhone 12

页面类型: vue

打包方式: 云端

项目创建方式: CLI

CLI版本号: 4.4.6

示例代码:

就是最简单的示例代码

<template>  
    <view class="content">  
        <image class="logo" src="../../static/logo.png" />  
        <view>  
            <text class="title">Uni-APP{{title}}</text>  
        </view>  
    </view>  
</template>  

<script lang="ts">  
  import { Vue, Component } from 'vue-property-decorator';  
    @Component({})  
    export default class index extends Vue {  
        private title: any = "Hello"  

        onLoad() {    
            console.log(this.title, '11111');    
        }    
    };  
</script>

操作步骤:

如上

预期结果:

真机模式下运行正常

实际结果:

真机模式下运行报错

bug描述:

运行为H5时完全正常, 运行为真机调试时报错如下

16:43:32.435  [Vue warn]: Error in data(): "TypeError: _super.apply is not a function. (In '_super.apply(this, arguments)', '_super.apply' is undefined)"  
16:43:32.459 (found at pages/index/index.vue:1) __ERROR   
16:43:32.481  TypeError: _super.apply is not a function. (In '_super.apply(this, arguments)', '_super.apply' is undefined) __ERROR   
16:43:32.506  undefined, 11111 at pages/index/index.vue:11   
16:43:32.525  [Vue warn]: Property or method "title" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
2021-06-08 17:16 负责人:无 分享
已邀请:
r***@hotmail.com

r***@hotmail.com (作者)

问题解决了, 记录一下, 因为tsconfig.json 的配置问题。

{  
  "compilerOptions": {  
    "target": "esnext", // 我原本设置的是es5 所以浏览器里是正常的, 但是app里就有问题, 设置成esnext 就 两端都正常了  
   }  
}

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