Use v-bind for prop destructuring
Use v-bind
as kind of a “prop destructuring” instead of passing multiple object properties into a component as props.
<template>
<post
:id="post.id"
:title="post.title"
:author="post.author"
/>
<!-- This (↑) is the same as this (↓) -->
<post v-bind="post" />
</template>
<script>
// <post> component definition
export default {
props: {
id: Number,
title: String,
author: Object
}
}
</script>
This tip originally appeared as a tweet.