H5W3
当前位置:H5W3 > 其他技术问题 > 正文

【前端问题精选】vue-property-decorator @prop 如何定义 Array

'use strict'

import Vue from 'vue'
import { Prop, Watch } from 'vue-property-decorator'

interface ITabs {
    name: string
    value: string
}

export default class extends Vue {
    @Prop({
        type: Array,
        default() {
            return []
        }
    })
    public tabs!: ITabs[] // TS2416
}

TS2416: Property ‘tabs’ in type ‘default’ is not assignable to the
same property in base type ‘object & Record<never,any> & Vue’. Type
‘ITabs[]’ is not assignable totype ‘{ name: “”; value: “”; }[] |
undefined’. Type ‘ITabs[]’ is not assignable to type ‘{ name: “”;
value: “”; }[]’. Type ‘ITabs’ is not assignable to type ‘{ name: “”;
value: “”; }’. Types of property ‘name’ are incompatible. Type
‘string’ is not assignable to type ‘””‘.

回答:

export default class extends Vue {
    @Prop({
        type: Array,
        default() {
            return []
        }
    })
    public tabs 
}

回答:

你那接口是对象的接口。数组这样写interface FuckArr {

                  [index: number]: any
                }

本文地址:H5W3 » 【前端问题精选】vue-property-decorator @prop 如何定义 Array

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址