复现步骤
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项目,可运行成功,但是浏览器报错,见附件