zoukankan      html  css  js  c++  java
  • 22.VUE学习之-replice删除当前评论条数

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <!--<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>-->
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
    <div id="hdcms">
        <li v-for="(v,k) in comments">
            <!--把当前为第几次传给remove函数-->
            {{k}}=>{{v.content}} <button v-on:click="remove(k)">删除</button>
        </li>
        <textarea v-model="current_content" cols="30" rows="10"></textarea><br>
        <button v-on:click="push('end')">发表到后面</button>
        <button v-on:click="push('pre')">发表到前面</button>
        <br>
        <button v-on:click="del('last')">删除最后一条评论</button>
        <button v-on:click="del('first')">删除第一条评论</button>
    </div>
    <script>
        var app = new Vue({
            el: '#hdcms',
            data: {
                //当前用户输入内容
                current_content: '',
                comments: [
                    {content: '后盾人'},
                    {content: '向军老师'},
                ]
            },
            methods: {
                remove(k){
                    this.comments.splice(k,1); //循环从当前条数开始移到1条数据
                },
                push(type){
                    var content = {content: this.current_content}
                    switch (type) {
                        case 'end':
                            this.comments.push(content);
                            break;
                        case 'pre':
                            this.comments.unshift(content);
                            break;
                    }
                    this.current_content = '';
                },
                del(type){
                    switch (type) {
                        case 'last':
                            this.comments.pop();
                            break;
                        case 'first':
                            this.comments.shift();
                            break;
                    }
                }
            }
        });
    </script>
    </body>
    </html>
    

    效果:

  • 相关阅读:
    多线程
    关于并发和并行
    文件系统
    java.util.Arrays类
    程序管理与SElinux
    用户和用户组管理总结
    useradd和adduser
    打印可见字符
    cmd中控制某个命令执行多少次
    keras模块之-优化器(optimizers)--笔记
  • 原文地址:https://www.cnblogs.com/haima/p/10236863.html
Copyright © 2011-2022 走看看