y***@163.com
y***@163.com
  • 发布:2021-03-01 19:14
  • 更新:2021-03-11 15:39
  • 阅读:557

新版本 vue-cli创建的uni-app,ts的static方法报错

分类:uni-app

复现步骤
1、使用vue create -p dcloudio/uni-preset-vue my-project创建typescript项目
2、添加文件src/A.ts,内容如下

class A {  
 static  test() {  
    return 'aa'  
  }  
}  

export default A;  

3、在page/index.vue中引入A,并使用test方法

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

<script lang="ts">  
import Vue from "vue";  
import A from "@/utils/A";  

export default Vue.extend({  
  data() {  
    return {  
      title: "Hello",  
    };  
  },  
  onLoad() {},  
  methods: {  
    showTime() {  
      return A.test();  
    },  
  },  
});  
</script>  

<style>  
.content {  
  display: flex;  
  flex-direction: column;  
  align-items: center;  
  justify-content: center;  
}  

.logo {  
  height: 200rpx;  
  width: 200rpx;  
  margin: 200rpx auto 50rpx auto;  
}  

.text-area {  
  display: flex;  
  justify-content: center;  
}  

.title {  
  font-size: 36rpx;  
  color: #8f8f94;  
}  
</style>  

4、yarn serve项目,可运行成功,但是浏览器报错,见附件

2021-03-01 19:14 负责人:无 分享
已邀请:
DCloud_UNI_GSQ

DCloud_UNI_GSQ

参考一下 https://ask.dcloud.net.cn/question/117584

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