Answer the question
In order to leave comments, you need to log in
Passing an array to props?
Hello. Tell me please. When passing an array through props, the value of the variable in data is not updated. The pickeds
variable is not updated when the value of the passed value changes when we move to the next element.
<app-some :value='items[activeId].value' ></app-some>
Vue.component('app-some', {
props: ['value'],
data() {
return {
pickeds: this.value
}
},
template: `
<div>
<label v-for='(picked, index) in pickeds' style='margin: 15px' :key='index'>
<input type='checkbox' :checked='pickeds[index]'> {{ index }}
</label>
</div>`
});
new Vue({
el: '#app',
template: `
<div>
<app-some :value='items[activeId].value' ></app-some>
<button :disabled='activeId===0' @click='activeId--' >Назад</button>
<button :disabled='activeId===items.length-1' @click='activeId++' >Далее</button>
<pre>{{ items[activeId].value }} </pre>
</div>`,
data() {
return {
activeId: 0,
items: [ { value: [false, true, false] }, { value: [true, true, false] }]
}
}
})
Answer the question
In order to leave comments, you need to log in
The point is that the value of pickeds is only set once, when the app-some bean is instantiated, so it's weird to expect it to change - you don't do that anywhere.
I don’t know what exactly you need, but ... To switch the checkboxes, there are options:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question