Викторина: кнопка плюс
Покупатель выбирает, сколько капучино ему нужно. Кнопка − работает, а + ничего не делает, и консоль пишет [Vue warn]: Set operation on key "count" failed: target is readonly. Загляните и в App.vue, а затем щёлкните по строке с ошибкой в Quantity.vue.
1<script setup>
2defineProps({
3 count: { type: Number, required: true },
4});
5const emit = defineEmits(["less", "more"]);
6</script>
7
8<template>
9 <div class="quantity">
10 <button @click="emit('less')">−</button>
11 <span>{{ count }}</span>
12 <button @click="count++">+</button>
13 </div>
14</template>
15
16<style scoped>
17.quantity {
18 display: flex;
19 gap: 12px;
20 align-items: center;
21}
22
23button:disabled {
24 background: #b8b0a8;
25 cursor: default;
26}
27</style>