zoukankan      html  css  js  c++  java
  • Vue 示例

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <div id="app">
            <fieldset>
                <legend>信息录入</legend>
                <div>
                    <label>
                        name:
                        <input type="text" placeholder="name" v-model.trim="newPerson.name">
                    </label>
                </div>
                <div>
                    <label>
                        age:
                        <input type="text" placeholder="age" v-model.trim="newPerson.age">
                    </label>
                </div>
                <div>
                    <label>
                        phone:
                        <input type="text" placeholder="phone" v-model.trim="newPerson.phone">
                    </label>
                </div>
                <div>
                    <label>
                        sex:
                        <select v-model="newPerson.sex">
                            <option value="男"></option>
                            <option value="女"></option>
                        </select>
                    </label>
                </div>
                <button @click="addPerson">add</button>
            </fieldset>
    
            <table border="1">
                <thead>
                <tr>
                    <th>id</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>手机</th>
                    <th>删除</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(person,index) in persons" :key="person.id">
                    <td>{{person.id}}</td>
                    <td>{{person.name}}</td>
                    <td>{{person.sex}}</td>
                    <td>{{person.age}}</td>
                    <td>{{person.phone}}</td>
                    <td><button @click="delPerson(index)">删除</button></td>
                </tr>
                </tbody>
            </table>
    
        </div>
        <script src="js/vue.3.2.2.js"></script>
        <script>
            // 1、创建Vue的实例对象
            const app = Vue.createApp({
                data(){//定义数据
                    return {
                        msg:'你好!',
                        persons:[
                            {id:1,name:'张三',age:20,sex:'',phone:'13333333333',friends:['李四','王五']},
                            {id:2,name:'李四',age:24,sex:'',phone:'13333333334',friends:['张三','王五']},
                            {id:3,name:'王五',age:28,sex:'',phone:'13333333335',friends:['李四','张三']}
                        ],
                        newPerson:{name:'',age:'',sex:'',phone:'',friends:[]}
                    }
                },
                methods:{
                    delPerson(index){
                        this.persons.splice(index,1);
                    },
                    addPerson(){
                        const {name,age,sex,phone} = this.newPerson;
                        if(!name || !age || !sex || !phone){
                            alert("数据不完整");
                            return;
                        }
                        this.persons.push(this.newPerson;
                        this.newPerson = {name:'',age:'',sex:'',phone:'',friends:[]};
                    }
                }
            }).mount('#app');
        </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <div id="app">
            <fieldset>
                <legend>信息录入</legend>
                <div>
                    <label>
                        name:
                        <input type="text" placeholder="name" v-model.trim="newPerson.name">
                    </label>
                </div>
                <div>
                    <label>
                        age:
                        <input type="text" placeholder="age" v-model.trim="newPerson.age">
                    </label>
                </div>
                <div>
                    <label>
                        phone:
                        <input type="text" placeholder="phone" v-model.trim="newPerson.phone">
                    </label>
                </div>
                <div>
                    <label>
                        sex:
                        <select v-model="newPerson.sex">
                            <option value="男"></option>
                            <option value="女"></option>
                        </select>
                    </label>
                </div>
                <button @click="addPerson">add</button>
            </fieldset>
    
            <table border="1">
                <thead>
                <tr>
                    <th>id</th>
                    <th>姓名</th>
                    <th>性别</th>
                    <th>年龄</th>
                    <th>手机</th>
                    <th>删除</th>
                </tr>
                </thead>
                <tbody>
                <tr v-for="(person,index) in persons" :key="person.id">
                    <td>{{person.id}}</td>
                    <td>{{person.name}}</td>
                    <td>{{person.sex}}</td>
                    <td>{{person.age}}</td>
                    <td>{{person.phone}}</td>
                    <td><button @click="delPerson(index)">删除</button></td>
                </tr>
                </tbody>
            </table>
    
        </div>
        <script src="js/vue.3.2.2.js"></script>
        <script>
            // 1、创建Vue的实例对象
            const app = Vue.createApp({
                data(){//定义数据
                    return {
                        msg:'你好!',
                        persons:[
                            {id:1,name:'张三',age:20,sex:'',phone:'13333333333',friends:['李四','王五']},
                            {id:2,name:'李四',age:24,sex:'',phone:'13333333334',friends:['张三','王五']},
                            {id:3,name:'王五',age:28,sex:'',phone:'13333333335',friends:['李四','张三']}
                        ],
                        newPerson:{name:'',age:'',sex:'',phone:'',friends:[]}
                    }
                },
                methods:{
                    delPerson(index){
                        this.persons.splice(index,1);
                    },
                    addPerson(){
                        const {name,age,sex,phone} = this.newPerson;
                        if(!name || !age || !sex || !phone){
                            alert("数据不完整");
                            return;
                        }
                        this.persons.push(this.newPerson;
                        this.newPerson = {name:'',age:'',sex:'',phone:'',friends:[]};
                    }
                }
            }).mount('#app');
        </script>
    </body>
    </html>
  • 相关阅读:
    与你一起学习MS Project基础篇:Project基础应用
    【项目管理工具】Microsoft Office Project 介绍
    学习Microsoft Visio(3)
    学习Microsoft Visio(2)
    学习Microsoft Visio(1)
    为什么管理人员都喜欢用Visio画图
    用Visio画流程图
    使用VISIO绘制组织结构图的操作方法
    C#(99):HttpClient网络HTTP请求和相应
    中国的名优绿茶
  • 原文地址:https://www.cnblogs.com/mingforyou/p/15157777.html
Copyright © 2011-2022 走看看