The Delightful World of Vue Part 2
Accidentally Modifying Prop Objects
Start your All-Access Pass to unlock this challenge
Buy Access Login

Challenge 1 / 1

Imagine you have this component that renders the name of a Pizza object, which you can in turn modify by typing text into an input element:

<template>
    <label>Name:</table>
    <pizza-name-input :pizza="pizza" />
</template>

<script>
import { getPizza } from '@/services/get-pizza';
import PizzaNameInput from '@/components/pizza-name-input';

export default {
    name: 'PizzaFormField',
    components: {
        PizzaNameInput,
    },
    data() {
        pizza: null,
    },
    async created() {
        this.pizza = (await getPizza()).data['hydra:member'];
    },
};
</script>
<template>
    <input type="text" v-model="pizza.name" />
</template>

<script>
export default {
    name: 'PizzaNameInput',
    props: {
        pizza: {
            type: Object,
            required: true,
        },
    },
};
</script>

What is the mistake we've just made here?

Select your answer
Skip challenges and go to theNext Chapter

Turn Challenges Off?

All further challenges will be skipped automatically.
You can re-enable challenges at any time on this page or from your account page.