vue實現簡易留言板


首先引入vue.js

<script src="vue.js"></script>

布局

<div id="div">
    <input type="text" v-model="username" @keyup.enter="add()">
    <input type="button" value="按鈕" @click="add()">
    <div v-show="this.arr.length ==0">暫無留言</div>
    <ul>
        <li v-for="item in arr">{{item}}
            <a href="javascript:;" @click="remove($index)">刪除</a>
        </li>
    </ul>
</div>

js

 <script>
        window.onload = function () {
            new Vue({
                el: '#div',
                data: {
                    username: '',
                    arr: []
                },
                methods: {
                    add: function () {
                        this.arr.unshift(this.username);
                        this.username = '';
                    },
                    remove:function (index) {
                        this.arr.splice(index,1);
                    }
                }
            });
        }
    </script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM