Why a ts-class-based vue-component's static method, which is declared in .vue, can only work in a .vue's script block?
steps to reproduce
- use vue-cli3 to init a typescript project and add shims-vue.d.ts
declare module "*.vue" {
import Vue from "vue";
export default Vue;
}
- add Comp.vue file in your project as below
// Comp.vue
<template>
<div></div>
</template>
<script lang="ts">
import { Component, Vue, Prop } from "vue-property-decorator";
@Component
export default class Comp extends Vue {
mounted() {
}
created(){
}
static notWorkFunc(){
//anything
}
}
export function anotherNotWorkFunc(){
//anything
}
</script>
- add test.ts and test.vue in your project with specific code as below
test.vue
<script lang="ts">
import ComP,{anotherNotWorkFun} from "./Comp.vue";
ComP.notWorkFunc()
anotherNotWorkFun()
</script>
test.ts
import ComP,{anotherNotWorkFun} from "./Comp.vue";
ComP.notWorkFunc()
anotherNotWorkFun()
As you can see
in .ts not work
in .vue work
I don't know the reason...
The repo is https://github.com/WilkinWendy/vue-ts-problem.
The democode is in ./src/demo
FYI

