new Vue({
el: "#app",
data: {
todos: [
{ text: "Learn JavaScript", done: false },
{ text: "Learn Vue", done: false },
{ text: "Play around in JSFiddle", done: true },
{ text: "Build something awesome", done: true }
]
},
methods: {
toggle: function(todo){
todo.done = !todo.done
}
},
mounted: function() {
// This creates a pointer!! Changes to foo modify todos!!!
let foo = this.todos;
foo.pop();
foo.pop();
foo.push({ text: "This should not bleed back into todos", done: true });
// This creates a copy of the data. Changes to bar no not modify todos
// Use lodash to clone only the data: let bar = _.cloneDeep(this.todos);
// https://stackoverflow.com/questions/48363604/vuejs-copying-data-object-and-removing-property-will-remove-the-property-from-or
let bar = _.cloneDeep(this.todos);
bar.pop();
bar.pop();
bar.push({ text: "Does not bleed", done: true });
},
})
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.