哇撒米
哇撒米
  • 发布:2020-03-13 16:12
  • 更新:2020-09-25 18:49
  • 阅读:2516

uni-app开发app,typescript中使用vue-class-component或者vue-property-decorator报错

分类:uni-app

1、HbuilderX 2.6.1.20200226 创建一个默认模板的uni-app项目
2、修改pages/index/index.vue为如下(只修改了script里面的代码):

<script lang="ts">  
    import Vue from 'vue';  
    import Component from 'vue-class-component';  

    @Component  
    export default class Index extends Vue {  
        title = 'hello';  
    }  
</script>

或者

<script lang="ts">  
    import {  
        Component,  
        Vue,  
    } from 'vue-property-decorator';  

    @Component  
    export default class Index extends Vue {  
        title = 'hello';  
    }  
</script>

3、运行到夜神模拟器V6.6.0.0018(Android版本号5.1.1)
4、问题:
1)HbuilderX控制台报错:TypeError: _getPrototypeOf(Index).apply is not a function. (In '_getPrototypeOf(Index).apply(this, arguments)', '_getPrototypeOf(Index).apply' is undefined)

2)app页面显示了一个uni-app图标,“hello”文字没有显示出来

2020-03-13 16:12 负责人:无 分享
已邀请:
x***@foxmail.com

x***@foxmail.com - 90后

跟你是同样的问题用@Component方式写的无效,用Vue.extend() 方式写的正常。
请问有解决方案了吗?

1***@qq.com

1***@qq.com

一样 求官方解决

1***@qq.com

1***@qq.com

V3 编译时会报错。V2为正常

山有扶苏

山有扶苏

试试:
import Vue from 'vue'
import { Component, Watch } from 'vue-property-decorator'

@Component({
name: 'index',
components: {
}
})

export default class Index extends Vue{
title= 'title123'

onLoad() {  
    console.log(this.title)  
}  

}

nick_ni

nick_ni - 开发使我快乐

解决了吗?同样的问题

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