【发布时间】:2019-09-04 20:53:44
【问题描述】:
我最近开始使用带有 typescript 的 vue 类组件,但找不到用导入的实用程序方法装饰组件类的方法。我正在使用nuxt-property-decorator 来装饰我的组件。
我已经尝试添加方法,就像我在没有打字稿的 vue 组件中那样:
import doSomething from './somewhere';
<script>
export default {
methods: {
doSomething,// I'd do this without typescript, works as expected
},
}
</script>
<script lang="ts">
import Vue from 'vue';
import {Component} from 'nuxt-property-decorator';
import doSomething from './somewhere';
@Component
export default class MyCustomClass extends Vue {
doSomething, // Doesn't, "Property or method doSomething is not defined on the instance but referenced during render..."
hacky() {
return doSomething(); // I guess I could do it this way, but this looks like a very hacky way
}
}
</script>
【问题讨论】:
标签: typescript vuejs2 nuxt.js