zoukankan      html  css  js  c++  java
  • 022——VUE中remove()方法的使用:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>vue中的变异方法:splice()方法</title>
        <script type="text/javascript" src="vue.js"></script>
    </head>
    <body>
    <div id="demo">
        <li v-for="(v,k) in comments">
            {{v.content}}
            <button v-on:click="remove(k)">删除</button>
        </li>
        <textarea rows="10" cols="20" v-model="current"></textarea><br/>
        <button v-on:click="push('first')">在数据前面增加</button>
        <button v-on:click="push('last')">在数据后面增加</button>
        <br>
        <button v-on:click="del('first')">删除第一个数据</button>
        <button v-on:click="del('last')">删除最后一个数据</button>
    </div>
    <script type="text/javascript">
    new Vue({
        el:"#demo",
        data:{
            current:"",
            comments:[
                {content:'PHP'},
                {content:'JAVA'}
            ]
        },
        methods:{
            //增加数据的方法:
            push(type){
                var content={content:this.current};
                switch (type){
                    case 'first':
                        this.comments.unshift(content);
                        break;
                    case 'last':
                        this.comments.push(content);
                        break;
                }
                this.current="";
            },
            //删除数据的方法:
            del(type){
                switch (type){
                    case 'first':
                        this.comments.shift();
                        break;
                    case 'last':
                        this.comments.pop();
                        break;
                }
            },
            //点击删除,删除对应的数据信息:
            remove(k){
                this.comments.splice(k,1);
            }
        }
    });
    </script>
    </body>
    </html>
    

      

  • 相关阅读:
    压缩感知的由来
    VS2010自动崩溃问题
    随机过程好书推荐
    Kernel PCA
    稀疏性与L1范数
    豆瓣关于计算机视觉的书评及介绍
    压缩感知测量矩阵的研究现状(转)
    信号的功率谱、能量谱、频谱的区别(转)
    vc++ & matlab 换行符号
    arg min 的含义
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8107829.html
Copyright © 2011-2022 走看看