【问题标题】:Declare typescript interface props in vue.js component在 vue.js 组件中声明 typescript 接口道具
【发布时间】:2020-10-26 09:29:40
【问题描述】:

我想在 typescript 的单个对象中定义 vue 组件道具。

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;

    .....
}

我可以在基于类的组件中像上面那样做。

但是如何使用 Vue.extend() 在组件中做到这一点?

【问题讨论】:

    标签: javascript typescript vue.js vuejs2 vue-props


    【解决方案1】:

    试试这个语法

    props: {
      foo: {
        type: Object as () => IFoo
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-12-01
      • 2018-11-26
      • 1970-01-01
      • 2022-07-29
      • 1970-01-01
      • 2019-12-27
      • 2013-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多