To start our component, we can create our Vue project with Vue-CLI, as we did in the 'Creating Your first project with Vue CLI' recipe in Chapter 2, Introducing TypeScript and the Vue Ecosystem, or use the project from the 'Accessing your children components data' recipe.
Follow these steps to create a dynamic injected component:
- Open the StarRating.vue component.
- In the <script> part of the component, we need to create a computed property with a new computed value called starComponent. This value will check whether the user has voted. If they haven't, it will return the StarRatingInput component; otherwise, it will return the StarRatingDisplay component:
<script> import StarRatingInput from './StarRatingInput.vue'; import StarRatingDisplay from './StarRatingDisplay.vue'; export default { name: 'StarRating', components: { StarRatingDisplay, StarRatingInput }, props: { maxRating: { type...