{{content|safe}} diff --git a/src/js/components/ListComp.vue b/src/js/components/ListComp.vue index 630e5ed..e9725a8 100644 --- a/src/js/components/ListComp.vue +++ b/src/js/components/ListComp.vue @@ -1,12 +1,15 @@ @@ -15,24 +18,22 @@ import Vue from "vue"; export default { props: { startlist: { - type: Array, - default: function() { - return [{ message: "Add items to me" }]; - } + type: String, + default: JSON.stringify([{ message: "Add items to me" }]) } }, data: function() { return { newitem: { message: "Enter text here" }, - list: [].concat([this.startlist]) + list: [].concat(JSON.parse(this.startlist)) }; }, - mounted: function() { - console.log(this.startlist); - }, methods: { addItem: function(e) { this.list = this.list.concat([Object.assign({}, this.newitem)]); + }, + removeItem: function(e) { + this.list = this.list.slice(0, e).concat(this.list.slice(e + 1)); } } }; diff --git a/src/js/main.js b/src/js/main.js index 15e6989..30d1399 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -15,6 +15,6 @@ Array.prototype.forEach.call(document.querySelectorAll(".ListComp"), function( elem ) { new Vue({ - render: h => h(ListComp, { props: { message: elem.dataset.list } }) + render: h => h(ListComp, { props: { startlist: elem.dataset.startlist } }) }).$mount(elem); });