我正在寻找在 Vuejs 类 Component 中声明一个 typescript 接口 Props,就像我们可以用 React Component 做的那样。
它看起来像这样:
import {Component, Prop, Vue} from 'vue-property-decorator'
export class Props extends Vue
{
classElement :string
}
@Component
export default class Menu extends Vue<Props>
{
public props :Props;
constructor(props)
{
super(props);
console.log(props); // return undefined
}
mounted()
{
console.log(this.props.classElement); // return undefined
}
}
有没有办法做到这一点?
原文由 BrownBe 发布,翻译遵循 CC BY-SA 4.0 许可协议
现在你可以在 Prop() 装饰器中使用
{type: Object as () => User}
像这样: