https://www.youtube.com/watch?v=-wvXgq3UU7c
npm i --save-dev @vinli/tune-up
use responsibly, never v-html user provided data
default props are great for simple things like Strings and Numbers, but can add lots of boilerplate if your prop is a Function, Array, or Object. So instead of providing a default for these prop types, make sure references to the these props are fault tolerant.
props: {
myThing: {
type: Object
}
},
methods: {
getSubthings () {
if (this.myThing.id) {
axios.get(`/api/v1/things${this.myThing.id}/subthings`)
}
}
}
This isn't a perfect solution, but cases where there is not a sensible default (like when have a uuid that's used for network requests) made us lean this way. It just felt a little more sane than coding up stuff like:
props: {
myThing: {
type: Object,
default: () => {
return {
name: 'pizza',
id: 'some_default_id'
}
}
}
},
methods: {
getSubthings () {
if (this.myThing.id !== 'some_default_id') {
axios.get(`/api/v1/things${this.myThing.id}/subthings`)
}
}
}
We've found this hard to respect in practice when using scoped slots. Maybe we'll change our minds!