In a Vue component, I have this:
JavaScript
x
7
1
props: {
2
foo: Boolean
3
},
4
mounted() {
5
console.log(this.foo)
6
}
7
If I call my component without foo
:
JavaScript
1
2
1
<component/>
2
I read false
on the console. I would like to get null
if the property is not given and the boolean value elsewhere.
How can I get this?
Advertisement
Answer
You could add default value :
JavaScript
1
7
1
props: {
2
foo: {
3
type:Boolean,
4
default: null
5
}
6
},
7