首页 > 其他 > 详细

vue实现简易留言板

时间:2017-07-11 21:54:49      阅读:453      评论:0      收藏:0      [点我收藏+]

首先引入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>

 

vue实现简易留言板

原文:http://www.cnblogs.com/4thmonth/p/7152733.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!