This is my "Test.vue"components
<template>
<div>
<div>
<button @click="decrenumber (id)">-</button>
<input name="test" type="text" :key="id" v-model.number="num">
<label for="test" ></label>
<button @click="increnumber (id)">+</button>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex';
export default {
name: 'Test',
data() {
return {
num: 0,
};
},
props: {
id: { type: Number, default: 0 },
},
methods: {
increnumber(id) {
this.num += 1;
this.$emit('update', this.num);
},
decrenumber(id) {
this.num -= 1;
this.$emit('update', this.num);
},
},
};
</script>
And I have 5 Test.vue components in my TestView.vue
<template>
<div >
<Test :id="index" v-for="(n,index) in 5" @update="selfUpdate"></Test>
</div>
</template>
<script>
import Test from '../components/Test.vue';
export default {
name: 'TestView',
components: {
Test,
},
data() {
return {
inputValue: 0,
};
},
methods: {
selfUpdate(num) {
this.inputValue = num;
this.$store.state.test.number = this.inputValue;
},
},
};
</script>
How can I store the value of each input from TestView.vue into vuex? I know it is possible to use array.push() but this keeps increasing How did I just make the input only exist in five indexes, If you enter the input in the same field, it can replace the old value