Vue组件和实例的关系
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TodoList</title>
</head>
<script src="./vue.js"></script>
<body>
<div id="root">
<div>
<input v-model="inputValue"/>
<button @click="submit">提交</button>
</div>
<ul>
<todo-item v-for="item in list" :content="item"></todo-item>
</ul>
</div>
<script>
Vue.component('todo-item', {
props: ['content'],
template: '<li @click="handleClick">{{content}}</li>',
methods: {
handleClick: function () {
console.log('---handleClick---');
}
}
})
new Vue({
el: '#root',
data: {
inputValue: '',
list: []
},
methods: {
submit: function () {
this.list.push(this.inputValue);
this.inputValue = '';
}
}
})
</script>
</body>
</html>