這個全局組件沒有效果,求大神指導(dǎo)
<!DOCTYPE html>
<html>
<head>
?? ?<meta charset="utf-8">
?? ?<title> todoList編寫</title>
?? ?<script src='./vue.js'></script>
</head>
<body>
?? ?<div id="toDo">
?? ??? ?<div>
?? ??? ??? ?<input v-model="inPutValue" >
?? ??? ??? ?<button @click="handelSubmit">提交</button>
?? ??? ?</div>
?? ??? ?<ul>
?? ??? ??? ?<!--? <li v-for='(item,index) of list' :key="index">{{item}}</li> -->
?? ??? ??? ?<todo-item> </todo-item>
?? ??? ?</ul>
?? ?</div>
?? ?
?? ?<script type="text/javascript">
?? ??? ?//定義組件??? 這是全局組件,template里是模板,相當(dāng)于定義一個標(biāo)簽
?? ??? ?Vue.component('todo-item',{
?? ??? ??? ?template:'<li>{{item}}</li>'
?? ??? ?})
?? ??? ?new Vue({
?? ??? ??? ?el:'#toDo',
?? ??? ??? ?data:{
?? ??? ??? ??? ?inPutValue:'please Write Here',
?? ??? ??? ??? ?list:[]
?? ??? ??? ?},
?? ??? ??? ?methods:{
?? ??? ??? ??? ?handelSubmit:function(){
?? ??? ??? ??? ??? ?this.list.push(this.inPutValue),
?? ??? ??? ??? ??? ?this.inPutValue=''
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?});
?? ?</script>
</body>
</html>
2018-12-27
item 沒有傳進來 ,默認為空? 把{{}}去掉會當(dāng)做字符串來處理 ,所以會顯示item??
2018-12-18
?Vue.component('todo-item',{
?? ??? ??? ?template:'<li>{{item}}</li>'
?? ??? ?})
這里的item不需要{{}}