Vue.Js 入门功能使用(制作留言板)

**使用Vue.js +WebStorm 开发,
可以实现保存,删除 全部删除等功能。**
备注:
v-on:click=”” 实现点击 可以简写成@click=“”。
v-model=”” 实现数据的绑定。
v-for=“vaue in items”

`Vue.Js 入门功能使用(制作留言板)_第1张图片

`Vue.Js 入门功能使用(制作留言板)_第2张图片


<html lang="en"
<head>
    <meta charset="UTF-8">
    <title>留言板title>
    <style>

    style>
    
    <link rel="stylesheet" href="lib/bootstrap.min.css">
    <script src="lib/jquery-3.2.1.min.js">script>
    <script src="lib/bootstrap.js">script>
    <script src="lib/vue.js">script>

    <script>
        window.onload=function () {
            new Vue({
                el:"#box",
                data:{
                    myData:[],
                    username:"",
                    age:"",
                    classroom:"",
                    currentIndex:""
                },
                methods:{
                    add:function(){
                        this.myData.push({
                            name:this.username,
                            age:this.age,
                            classroom:this.classroom
                        });
                        this.username="";
                        this.age="";
                        this.classroom="";
                    },
                    clearInput:function () {
                        this.username="";
                        this.age="";
                        this.classroom="";
                    },
                    deleteItem:function (index) {
                        this.myData.splice(index,1);
                    },
                    deleteAll:function () {
                        this.myData=[];
                    }

                }
            });
        };



    script>
head>
<body>
    <div class="container"  id="box">
        <form role="form">
            <div class="form-group">
                <label for="username" class="h5"> 用户名:label>
                <input type="text" id="username" class="form-control" placeholder="输入用户名" v-model="username">
            div>
            <div class="form-group">
                <label for="age" class="h5"> 年 龄:label>
                <input type="text" id="age" class="form-control" placeholder="输入年龄" v-model="age">
            div>
            <div>
                <label for="classroom" class="h5">班级label>
                <input type="text" id="classroom" class="form-control" placeholder="输入班级" v-model="classroom">
            div>
            <div class="form-group h3 ">
                <input type="button" value="添加" class="btn btn-primary" v-on:click= "add">
                <input type="button" value="重置" class="btn btn-danger" v-on:click="clearInput">
            div>
        form>

        
        <hr>
        <table class="table table-bordered table-hover" >
            <caption  class="h3 text-info text-center ">用户信息表caption>
            <tr class="text-info">
                <th class="text-center">序号th>
                <th class="text-center">用户名th>
                <th class="text-center">年龄th>
                <th class="text-center">班级th>
                <th class="text-center">操作th>
            tr>
            <tr class="text-center" v-for="(item,index) in myData">
                <td >{{index+1}}td>
                <td >{{item.name}}td>
                <td >{{item.age}}td>
                <td >{{item.classroom}}td>
                <td >
                    <input type="button" value="删除" class="btn btn-primary btn-sm" data-toggle="modal"
                           data-target="#layer"  v-on:click="currentIndex=index" >
                td>
            tr>
            <tr v-show="myData.length!=0">
                <td colspan="5" class="text-right">
                    <button class="btn btn-danger btn-sm" v-on:click="deleteAll">删除全部button>
                td>
            tr>
            <tr v-show="myData.length==0">
                <td colspan="5" class="text-center text-muted">
                    <p >暂无数据......p>
                td>
            tr>
        table>
        
        <div role="dialog" class="modal"  id="layer" >
            <div class="modal-dialog" >
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">
                            <span>×span>
                        button>
                        <h4 class="modal-title">确认要删除此行数据吗?h4>
                    div>
                    <div class="modal-body text-right" >
                        <button class="btn btn-primary" data-dismiss="modal">取消button>
                        <button class="btn btn-danger" data-dismiss="modal" v-on:click="deleteItem(currentIndex)">确认button>
                    div>
                div>
            div>

        div>
    div>
body>
html>

你可能感兴趣的:(html学习,vue-js)