亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Maven多模塊+SSM框架(六、 Vue.js漸進式框架配合Ajax的簡單使用 )

標簽:
Java WebApp Vue.js

前言

最近学习了Vue文档真的是非常友好,简单易懂,所以学习成本比较低,易上手。

建议学习时看官方文档(自我感觉比看视频效果好点) Vue.js 渐进式JavaScript 框架

添加Vue.js引用

在之前配置的“装饰页”中添加引用

建议先看Maven多模块+SSM框架(五、Bootstrop3+Sitemesh3网页布局和修饰的框架)

图片描述

添加studentInfo.js

图片描述

/**
 * Created by SongLiuxin on 2017/9/7.
 */
     //创建一个新的 Vue 实例
var app=new Vue({
    el: '#app',
    //数据对象
    data: {
        studentInfos : []
    },
    //加载时自动执行
    mounted() {
        this.getData(0)
    },
    //方法写这里
    methods: {
        getData: function (id) {
            $.ajax({
                type: "POST",
                url: "/studentApi/findAllStudentInfo.do",
                data: {id:id},
                dataType: "json",
                success: function (data) {
                 if(data.success)
                 {
                     app.studentInfos=data.result;
                 }
                 else
                 {
                     //调用Bootstrop中的模态框
                     $('#myModal').modal('show');
                     $("#myModalLabel").html("糟糕");
                     $("#modal-body").html("数据获取异常"+data.message);
                     $("#bt1").html("确定");
                     $("#bt1").attr("data-dismiss","modal");
                 }

                }
            });
        }
    },
    //过滤器
    filters: {
        studentSex:function(sex) {
            var stuSex="女";
            if(sex){
                stuSex="男";
            }
            return stuSex;
        }
    }
});

studentInfo.jsp页面添加

图片描述

<%--
  Created by IntelliJ IDEA.
  User: SongLiuxin
  Date: 2017/9/7
  Time: 13:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
    <title>学生信息</title>

</head>
<body onload="showFunction1(null,null)">
<!-- start: PAGE HEADER -->
<div class="row">
    <div class="col-sm-12">
        <!-- start: PAGE TITLE & BREADCRUMB -->
        <ol class="breadcrumb">
            <li><i class="clip-home-3"></i> <a
                    href="./${sessionScope.pathCode}/home.do"> 首页 </a>
            </li>

        </ol>
        <div class="page-header">
            <h3>学生信息</h3>
        </div>
        <!-- end: PAGE TITLE & BREADCRUMB -->
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <!-- start: TABLE WITH IMAGES PANEL -->
        <div class="panel-body">
            <div class="row"></div>
            <div class="panel-body" id="app">
                <table class="table table-striped table-bordered table-hover"style="TABLE-LAYOUT:fixed;WORD-BREAK:break-all">
                    <thead>
                    <tr>
                        <th width="5%"><small>序号</small></th>
                        <th width="15%"><small>学生ID</small></th>
                        <th width="15%"><small>姓名</small></th>
                        <th width="15%"><small>性别</small></th>
                        <th width="50%"><small>地址</small></th>
                    </tr>
                    </thead>
                    <tbody id="tbody">
                    <tr v-for="(studentInfo,index) in studentInfos">
                        <td>{{index+1}}</td>
                        <td>{{studentInfo.id}}</td>
                        <td>{{studentInfo.name}}</td>
                        <td>{{studentInfo.sex | studentSex }}</td>
                        <td>{{studentInfo.address}}</td>
                    </tr>

                    </tbody>
                </table>
            </div>

        </div>
    </div>
</div>
<script class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="../../../assets/myassets/js/student/studentInfo.js"></script>
</body>
</html>

显示结果

图片描述

未完待续~~~

GitHub地址:https://github.com/iamsongci/mytest_one

點擊查看更多內容
16人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
全棧工程師
手記
粉絲
218
獲贊與收藏
1546

關注作者,訂閱最新文章

閱讀免費教程

感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消