//No need to define the type with this one
props: ['myVariable', 'foo', 'something']
第二个
//With this one you can define what type the prop is and other different useful things!
props: {
myVariable: String, //You can define the type like this
anyOfTheFollowing: String/Object/Array, //You can also define multiple possible types
'kebab-case-like': Function, //Since vuejs is still javascript and the property 'props' is actually an object, you can define your props like this for kebab-case. You can also just use camelCase and use the kebab-case version in your template and it will still recognize it
customOne: MyCustomType, //You can in theory use classes you've defined aswell
foo: { //This is another way of defining props. Like an object
type: Number,
default: 1, //This is why this is mostly used, so you can easily define a default value for your prop in case it isn't defined
},
andAnotherOne: {
type: Array,
default: () => [], //With Arrays, Objects and Functions you have to return defaults like this since you need to return a new reference to it for it to be used
},
requiredOne: {
type: Object,
required: true //Another use for this. When it is marked as required and it isn't defined you'll get an error in the console telling you about it
}
}