vue局部组件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="./vuev2.5.21.js"></script> </head> <body> <div id="app"> <input type="text" v-model="inputValue"> <button @click="BtnClick">提交</button> <ul> <!-- <li v-for="item in list">{{item}}</li> --> <todo-item v-bind:content="item" v-for="item in list"></todo-item> </ul> </div> <script> // Vue.component("TodoItem",{ // props:["content"], // template:"<li>{{content}}</li>" // }); var todoItem={ props:["content"], template:"<li>{{content}}</li>" }; var app= new Vue({ el:"#app", components:{ TodoItem:todoItem }, data:{ inputValue:"", list:[], }, methods:{ BtnClick:function(){ // console.log(this.list); this.list.push(this.inputValue); this.inputValue=""; } } }) </script> </body> </html>
Sometimes you need to applaud yourself