Vue中props默认值正确写法:使用Array或Object时,需在默认值外层添加括号。
- 内容介绍
- 文章标签
- 相关推荐
本文共计279个文字,预计阅读时间需要2分钟。
1. 错误写法 + demo:json{ type: Array, default: []}ESLint语法报错:Invalid default value for prop demo: Props with type Object/Array must use a factory function to return the default value.
2. 正确写法:json{ type: Array, default: ()=> []}
1、错误写法
demo:{ type:Array, default:[] }
eslint语法报错:
Invalid default value for prop “demo”: Props with type Object/Array must use a factory function to return the default value.
2、正确的写法应该是:
本文共计279个文字,预计阅读时间需要2分钟。
1. 错误写法 + demo:json{ type: Array, default: []}ESLint语法报错:Invalid default value for prop demo: Props with type Object/Array must use a factory function to return the default value.
2. 正确写法:json{ type: Array, default: ()=> []}
1、错误写法
demo:{ type:Array, default:[] }
eslint语法报错:
Invalid default value for prop “demo”: Props with type Object/Array must use a factory function to return the default value.
2、正确的写法应该是:

