The other answers have noted that the reason your code doesn't work is because you shouldn't mutate properties. However, the reason the code in the fiddle doesn't work is because eee is passed a static array. In other words, since the value for eee is bound to an object hard coded into the property, that value is never converted into a reactive object.
Had you instead passed eee a data property, the array would have been converted into a reactive array and your code would work as you expect.
Vue.component('todo-item', {
props: ['todo'],
template: '<div>' +
'<li>{{ todo.text }}</li>' +
'<button v-on:click="reverseMessage">Reverse Message</button>' +
'</div>',
methods: {
reverseMessage: function() {
var reversed = this.todo.text.split('').reverse().join('');
this.todo.text = reversed;
}
}
});
Vue.component('todo-list', {
props: ['eee'],
template: '<div><todo-item' +
' v-for="item in eee"' +
' v-bind:todo="item"' +
' v-bind:key="item.id">' +
' </todo-item></div>',
});
var app7 = new Vue({
el: '#app-7',
data: {
todos: [{
id: 0,
text: 'Vegetables'
}, {
id: 1,
text: 'Cheese'
}, {
id: 2,
text: 'Whatever else humans are supposed to eat'
}]
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js"></script>
<div id="app-7">
<ol>
<todo-list v-bind:eee="todos"></todo-list>
</ol>
</div>
Note the change to the template:
<todo-list v-bind:eee="todos"></todo-list>
And the Vue:
var app7 = new Vue({
el: '#app-7',
data:{
todos: [{ id: 0, text: 'Vegetables' },{ id: 1, text: 'Cheese' },{ id: 2, text: 'Whatever else humans are supposed to eat' }]
}
})
Thats all I changed in the code to make it work as expected.
This is how reactive objects and arrays passed as properties work in Vue. From the documentation:
Note that objects and arrays in JavaScript are passed by reference, so
if the prop is an array or object, mutating the object or array itself
inside the child will affect parent state.
Vue will not complain if you mutate an object or array in this way. Where Vue will complain is if you attempted to set the object or array to a completely different object or array.
Whether that behavior is desired is a design decision. Sometimes you may want to take advantage of it and other times not.