<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script> </head> <body> <div id="app"> {{ message }} <input type="text" name="" id="" v-model="mytext"> <button @click="add">btn</button> <div v-show="datalist.length"> <ul> <li v-for="(data,index) in datalist"> {{data}} <button @click="del(index)">del</button> </li> </ul> </div> <div v-show="!datalist.length"> empty </div> </div> </body> <script> var app = new Vue({ el: '#app', data: { datalist:["123","234","567"], message: 'Hello Vue!', mytext:"" }, methods: { add(){ // alert("11"); this.datalist.push(this.mytext); }, del(index){ console.log(index); this.datalist.splice(index,1) } }, }) </script> </html>