zoukankan      html  css  js  c++  java
  • 20.VUE学习之-变异方法push的留言版实例讲解

    <!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 in comments">
            {{v.content}}
        </li>
    
        <!--当textarea里的内容改变时,会动态改变data/current_content-->
        <textarea v-model="current_content" cols="30" rows="10"></textarea><br>
        <button v-on:click="push">发表</button>
    </div>
    <script>
        var app = new Vue({
            el: '#hdcms',
            data: {
                //当前用户输入内容
                current_content:'',
                comments: [
                    {content: '测试一'},
                    {content: '测试二'},
                ]
            },
            methods:{
                push(){
                    //用data/current_content里动态改变的值,声明一条记录赋值给变量content
                    var content = {content:this.current_content}
                    //动态把content加入data/comments的数组里,动态的加入页面li列表里
                    this.comments.push(content);
                    //操作完后,把data/current_content里的值清空
                    this.current_content ='';
                }
            }
        });
    </script>
    </body>
    </html>
    

    效果:

  • 相关阅读:
    jq 自定义动画案例
    jq 左右轮播图案例
    hdu-5728 PowMod(数论)
    UVA-11892(组合游戏)
    UVA-12293(组合游戏)
    LA-5059(组合游戏)
    hdu-5724 Chess(组合游戏)
    hdu-5750 Dertouzos(数论)
    hdu-5748 Bellovin(LIS)
    hdu-5747 Aaronson(水题)
  • 原文地址:https://www.cnblogs.com/haima/p/10232744.html
Copyright © 2011-2022 走看看