Vue前端框架基礎+Element的使用( 三 )

  • 修改視圖
    <div id="app"><a ><input type="button" value="https://www.huyubaike.com/biancheng/新增"></a><br><hr><table id="brandTable" border="1" cellspacing="0" width="100%"><tr><th>序號</th><th>品牌名稱</th><th>企業名稱</th><th>排序</th><th>品牌介紹</th><th>狀態</th><th>操作</th></tr><tr v-for="(brand, i) in brands" align="center"><td>{{i+1}}</td><td>{{brand.brandName}}</td><td>{{brand.companyName}}</td><td>{{brand.ordered}}</td><td>{{brand.description}}</td><td>{{brand.status}}</td><td><a >修改</a> <a >刪除</a></td></tr></table></div>
  • 完整代碼展示
    <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title></head><body><div id="app"><a ><input type="button" value="https://www.huyubaike.com/biancheng/新增"></a><br><hr><table id="brandTable" border="1" cellspacing="0" width="100%"><tr><th>序號</th><th>品牌名稱</th><th>企業名稱</th><th>排序</th><th>品牌介紹</th><th>狀態</th><th>操作</th></tr><tr v-for="(brand, i) in brands" align="center"><td>{{i+1}}</td><td>{{brand.brandName}}</td><td>{{brand.companyName}}</td><td>{{brand.ordered}}</td><td>{{brand.description}}</td><td>{{brand.status}}</td><td><a >修改</a> <a >刪除</a></td></tr></table></div><script src="https://www.huyubaike.com/biancheng/js/vue.js"></script><script src="https://www.huyubaike.com/biancheng/js/axios-0.18.0.js"></script><script>new Vue({el:"#app",data(){return{// 注意此處為數組brands:[]}},// 當前頁面加載完成后發送AJAX請求,查詢數據mounted(){// Axios無法直接使用原生的thisvar _this = this;axios({method: "get",url: "http://localhost:8080//brand-demo-ajax/selectAll"}).then(function (resp) {// 接收后臺給到的數據,為JSON串,可自動反序列化為JavaScriptObjects_this.brands = resp.data;})}})</script></body></html>
  • 1.5.3 添加功能1.5.3.1 實現方式
    1. 點擊提交按鈕,發送ajax請求 , 攜帶表單JSON數據 , 使用v-model
    2. 后臺接收請求,查詢接收到的品牌數據
    3. 調用對應的service方法添加數據
    4. 響應成功標識
    5. 獲取數據,判斷是否添加成功,跳轉到查詢所有數據頁面
    1.5.3.2 編碼