Skip to content

Instantly share code, notes, and snippets.

@kevinruscoe
Created October 7, 2016 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinruscoe/06ee541553cd5d2f310bd1db50d02193 to your computer and use it in GitHub Desktop.
Save kevinruscoe/06ee541553cd5d2f310bd1db50d02193 to your computer and use it in GitHub Desktop.
Vue.component('People', require('./components/People.vue'));
Vue.component('Person', require('./components/Person.vue'));
const app = new Vue({
el: '#app'
});
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>index</title>
</head>
<body>
<div id="app">
<People></People>
</div>
<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
<template>
<ul id="People">
<Person v-for="(person, index) in people"
:name="person.name"
:age="person.age"
v-on:destroy="destroy"
></Person>
</ul>
</template>
<script>
export default {
data: function(){
return {
people: [
{
name: "Kevin",
age: 28
},
{
name: "Adam",
age: 24
}
]
}
},
methods: {
destroy: function(person){
this.people.splice(person, 1);
}
}
}
</script>
<template>
<li @click="destroy">
{{ name }} {{ age }}
</li>
</template>
<script>
export default {
props: ['name', 'age'],
methods: {
destroy: function(){
this.$emit('destroy', this);
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment