• vue案列


    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
        </head>
        <body>
            <div id="div2" v-bind:style="mystyle">
                    <section>
                        <h1>{{title}}</h1>
                            <table>
                                <tr>
                                    <th>id</th>
                                    <th>姓名</th>
                                    <th>性别</th>
                                </tr>
                                <tr v-for="person in persons">
                                    <td>{{person.id}}</td>
                                    <td>{{person.name}}</td>
                                    <td>{{person.sex}}</td>
                                    <td>
                                    <a href="#" @click="remove(person.id)">删除</a>
                                    </td>
                                </tr>    
                            </table>
                        </section>
                        <button @click="changeStyle"> 变色</button>
                        <div><input  v-model.number="person.id" ></div>
            <div><input  v-model.number="person.name" ></div>
            <div><input  v-model.number="person.age"></div>
                <button @click="submit">提交</button>
            </div>
            <script src="css/vues.js"></script>
            <script>
                var vm=new Vue({
                    el:"#div2",
                    data:{
                        title:'渲染数据',
                        persons:[{
                            name:'张三',
                            sex:'',
                            id:18
                        },
                        {
                            name:'李四',
                            sex:'',
                            id:22
                        },
                        {
                            name:'李四',
                            sex:'',
                            id:22
                        },
                        {
                            name:'王五',
                            sex:'',
                            id:38
                        },
                        ],
                        mystyle:"color:red",
                        person:{id:0,name:"",sex:0}
                    },
                    methods:{
                        changeStyle:function(){
                            var colors=["green","red","yellow"];
                            var randColor=colors[Math.floor(Math.random()*colors.length)];
                            this.mystyle="color:"+randColor;
                        },
                        submit:function(){
                                this.persons.push({
                                id:this.person.id,
                                name:this.person.name,
                                sex:this.person.sex,
                                });
                                console.log(this.persons);
                        },
                        remove:function(id){
                            this.persons=this.persons.filter((b) => b.id != id);
                        }
                    },
                    watch:{
                        id:function(n,o){
                            console.log(`修改后n:${n} 修改 o:${o}`)
                        }
                    },
                    computed:{
                        revMsg:function(){
                            return this.msg.split("").reverse().join("");
                        }
                    }
                });
            </script>
        </body>
        
    </html>

    运行效果:

  • 相关阅读:
    Chapter 7 Integrity(完整性), Views(视图), Security(安全性), and Catalogs(目录)
    Qt计时器
    linux命令:linux文件处理命令
    JSON.stringify()的不常见用法
    flex知识点归纳
    css伪类
    开发资源汇总
    Math.cbrt() Math.sqrt() Math.pow()
    代码开发注意事项和规范
    关于数组数据容易忽略的点
  • 原文地址:https://www.cnblogs.com/weibanggang/p/9969848.html
Copyright © 2020-2023  润新知