overus Asked:2022-07-01 18:34:43 +0000 UTC2022-07-01 18:34:43 +0000 UTC 2022-07-01 18:34:43 +0000 UTC 如果输入参数为空,如何为输入参数分配默认值? 772 该组件需要一个数组作为输入: props: { form: Object, }, 有一种情况this.form === null。如果它来null了,如何分配一个空数组而不是null? vue.js 1 个回答 Voted Best Answer MobiDevices 2022-07-01T19:24:00Z2022-07-01T19:24:00Z 您写道该组件需要一个数组,但您指定Object. 如果组件需要一个对象,那么这里是解决方案: props: { form: { type: Object, default: () => ({}) } } 对于数组: props: { form: { type: Array, default: () => [], } }
您写道该组件需要一个数组,但您指定
Object. 如果组件需要一个对象,那么这里是解决方案:对于数组: