1. <body>
    2. <script src='https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js'></script>
    3. <div id='myApp'>
    4. <input type="text" v-model.trim="add" @keyup.enter='hh'>
    5. <ol>
    6. <li v-for="(item,index) in arr">
    7. <b>{{item}}</b>
    8. <button @click='remove(index)'>删除</button>
    9. </li>
    10. </ol>
    11. </div>
    12. <script>
    13. new Vue({
    14. el: '#myApp',
    15. data: {
    16. add: '',
    17. arr: []
    18. },
    19. methods: {
    20. hh(e) {
    21. if (e.target.value.trim() != '') {
    22. this.arr.push(this.add)
    23. this.add = ''
    24. }
    25. },
    26. remove(i) {
    27. this.arr.splice(i, 1)
    28. }
    29. }
    30. })
    31. </script>
    32. </body>