Vue

by evzens

HTML

<div id="root">
<h2>
Component
</h2>

<input v-model="newMeal" @keyup.enter="addMeal">
<button @click="addMeal">
Add 
</button>
<ul>
  <li v-for="cat in cats">{{ cat.text }} </li>
</ul>
<hr>
<cat-list :cats="cats"></cat-list>
</div>

CSS

body {
  background: #20262E;
  padding: 20px;
}

#root {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

del {
  color: rgba(0, 0, 0, 0.3);
}

Vue

Vue.component('cat-list' , {
	props: ['cats'],
  template: `
  	<ul>
    	<li v-for="cat in cats">{{ cat.text }} </li> 
    </ul>
    `
})

new Vue({
  el: "#root",
  component: ['cat-list'],
  data: {
    cats: [
      { text: "Mys" },
      { text: "Jablko" },
      { text: "Meloun" },
      { text: "Ryba" }
    ],
    newMeal: ''
  },
  methods: {
  	addMeal: function() {
       this.cats.push({ text: this.newMeal})
       this.newMeal = ''
    }
  },
  filters: {
  	capitalize: function(value) {
    	return value.toUpperCase()
    },
    kitify: function(value) {
    	return value + 'y'
    }
  },
  created: function() {
  	console.log("created")
  },
  mounted: function() {
  	console.log("mounted")
  },
  updated: function() {
  	console.log("updated")
  },
  destroyed: function() {
  	console.log("destroyed")
  }
})