Asp.net+Vue2構建簡單記賬WebApp之五(vue.js構建記賬頁面)
小編:管理員 50閱讀 2022.08.19
一、編輯記賬頁面hello.vue
<template> <div> <div id="TopTitle"> <mt-header v-bind:title="msg"> </mt-header> <mt-field label="¥" placeholder="在此輸入記賬金額" type="number" v-model="money"></mt-field> </div> <div id="BillTypes" > <div v-for="item in billType" :key="item.id" class="item" v-on:click="Add(item.id)"> <div class="item_img"> <i class="fa fa-3x" v-bind:class="item.fontStyle"></i> </div> <span>{{item.name}}</span> </div> <div style="clear: both"></div> </div> </div> </template> <script> import { Toast } from 'mint-ui'; // 引入mint-ui彈窗,對于js要調用的還需要這樣引用一下。不知道為什么 export default { name: 'hello', data() { return { msg: '理財從記賬開始', billType: [], // 賬單數據 money: '', // 記賬的金額 } }, created() { this.$http.get('/bill/GetBillType').then(response => { this.billType = response.body.result.data; }, response => { Toast("獲取數據出錯") }); }, methods: { Add(m) { if (this.money == '') { Toast('請先輸入記賬金額,再選擇資金去向'); return; } ; this.$http.post('/bill/AddBills', { Money: this.money, BillTypeId: m, }).then(r => { if (r.body.result.result) { Toast({ message: '記賬成功', iconClass: 'icon icon-success' }); this.money = ''; } else { Toast(r.body.result.data); } }, r => { Toast("數據傳輸失敗"); }) }, } } </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> #TopTitle{ position: fixed; top: 0; width: 100%; background-color: #eee; z-index: 1; } #TopTitle div *{ border-style: none; } #BillTypes{ margin-top: 88px; position: relative; height: auto; background-color: #eee; } #BillTypes .item{ height: 100px; padding: 11px 15px; vertical-align: top; border-right: 1px solid #fff; border-bottom: 1px solid #fff; position: relative; float: left; width: 33.33333%; box-sizing: border-box; } #BillTypes .item .item_img{ clear: both; padding-bottom: 8px; } </style>復制二、發布查看效果
因為用到了后臺數據,所以要在asp.net端配合后臺才能查看效果。 我調試時,直接在本地部署了一個網站,網站地址指向的就是項目的web文件夾。然后瀏覽器輸入地址即可。為了方便,我將asp.net中homeControler進行了修改。
using System.Web.Mvc; using Abp.Web.Mvc.Authorization; namespace MyBill.Web.Controllers { // [AbpMvcAuthorize] public class HomeController : MyBillControllerBase { public ActionResult Index() { Response.Redirect("/mybill/dist/index.html"); return View(); } } }復制

這里寫圖片描述
三、總結1、使用vue-resource 來獲取/傳輸數據,更多方法參看官網 2、created() 不同vue2中新添的內容實現構建完成執行。更多參看下圖。

這里寫圖片描述
相關推薦
- Vue3(二)工程化開發方式做項目 工程化的開發方式這是開發中、大型項目的必備技能,網上資料也很多,這里只是一個簡單的綜合性的介紹。包括vue的全家桶、建立項目的幾種方式、UI庫的簡單使用等?梢院蜕弦黄腸nd方式做項目做一下對比。node.js,npm、cnpm、yarnnode.js執行 npm run serve ,…
- Hibernate Criterion 在查詢方法設計上能夠靈活的依據Criteria的特點來方便地進行查詢條件的組裝.Hibernate設計了CriteriaSpecification作為Criteria的父接口,以下提供了Criteria和DetachedCriteria.Criteria和DetachedCriteria的主要差別在于創建的形式不一樣,Criteria是在線的,所…