//header 模板内容
const header_template=`<header >
<h1 >todos</h1>
<input class="new-todo" placeholder="What needs to be done?" v-model="newtodo" @keyup.enter="@keyup.enter="heanderNewtodo"" @blur="@keyup.enter="heanderNewtodo"" >
</header>`
//子组件中定义好新的数据变量,以及向上进行传递数据
appheader={
props:['todos'],
data(){
return({
newtodo:''
})
},
template:header_template,
methods:{
heanderNewtodo(){
this.$emit('new-todos',this.newtodo) //传递数据给父组件
this.newtodo='' //将子组件输入框中内容清空
}
}
}