什么是typescript
什么是typescripttypescript 为 javaScript的超集,这意味着它支持所有都JavaScript都语法。它很像JavaScript都强类型版本,除此之外,它还有一些扩展的语法,如interface/module等。
typescript 在编译期会去掉类型和特有语法,生成纯粹的JavaScript。Typescript 5年内的热度随时间变化的趋势,整体呈现一个上升的趋势。也说明ts越来越️受大家的关注了。在vue中使用typescript时,需要引入vue-property-decorator库来兼容格式。vue-property-decoratorjavascript写法
Vue.component('blog-post', {
// 在 JavaScript 中是 camelCase 的
props: ['postTitle'],
template: '

{{ postTitle }}

'
})
Vue.component('blog-post', {
// 在 JavaScript 中是 camelCase 的
props: ['postTitle'],
template: '

{{ postTitle }}

'
})typescript写法
@Prop({

type: Array,

default: function(): Array {

return [];

}
})
label_list: Array | undefined;
@Prop({

type: Array,

default: function(): Array {

return [];

}
})
label_list: Array | undefined;typescript和javascript在用法的区别,主要是需要严格规定label_list的类型。但是,在vue里面,prop是不能赋初始值的。这个规则和typescript会发生矛盾,因此定义类型需要加undefined,避免typescript转义告警。在代码中使用label_list时,需要用label_list as Array的语法,转换成正常的数组格式参考链接
vue propsvue propsvue-property-decoratorvue-property-decorator总结总结总结以上所述是小编给大家介绍的vue框架中props的typescript用法详解,希望对大家有所帮助!