Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果未传递任何内容,则Vue.js将prop值设置为空_Javascript_Typescript_Vue.js - Fatal编程技术网

Javascript 如果未传递任何内容,则Vue.js将prop值设置为空

Javascript 如果未传递任何内容,则Vue.js将prop值设置为空,javascript,typescript,vue.js,Javascript,Typescript,Vue.js,所以我有这个折扣界面: export interface Discount { id: number name: string type: string } 我在Vue.js应用程序中的道具上使用它,如下所示: export default class DiscountsEdit extends Vue { @Prop({ default: () => {} }) discount!: Discount; } 我使用twig模板引擎,将空折扣数组传递到V

所以我有这个折扣界面:

export interface Discount {
    id: number
    name: string
    type: string
}
我在Vue.js应用程序中的道具上使用它,如下所示:

export default class DiscountsEdit extends Vue {
    @Prop({ default: () => {} }) discount!: Discount;
}
我使用twig模板引擎,将空折扣数组传递到Vue组件中。我希望整个折扣对象具有空变量值,如:

id: 0
name: ''
type: ''

是否可以在Vue.js端自动设置,或者在发送到Vue端之前,我必须将这些值定义为空?

对象属性的默认值可能如下所示:

 @Prop({ default: () => ({id:0,name:'',type:''}) }) discount!: Discount;