Asp.net+Vue2構(gòu)建簡(jiǎn)單記賬WebApp之一(設(shè)計(jì))
Asp.net+Vue2構(gòu)建簡(jiǎn)單記賬WebApp之二(使用ABP迅速搭建.Net后臺(tái))
Asp.net+Vue2構(gòu)建簡(jiǎn)單記賬WebApp之三(使用Vue-cli構(gòu)建vue.js應(yīng)用)
Asp.net+Vue2構(gòu)建簡(jiǎn)單記賬WebApp之四(vue.js構(gòu)建記賬主頁面)
Asp.net+Vue2構(gòu)建簡(jiǎn)單記賬WebApp之五(vue.js構(gòu)建記賬頁面)
Asp.net+Vue2構(gòu)建簡(jiǎn)單記賬WebApp之六(vue.js構(gòu)建記賬統(tǒng)計(jì)頁面)
源碼下載
一、安裝我們所需要的一些庫
cnpm install mint-ui -S // 安裝mint-ui庫,ui庫,cnmp是按照淘寶鏡像后的用法,用法和npm一樣。-s是將庫添加到項(xiàng)目的package.json文件中。
cnpm install echarts -S // 安裝echarts庫。用于繪制圖表
cnpm install vue-resource -S // 相當(dāng)于ajax取數(shù)據(jù)用的
package.json 文件中可以看見我們當(dāng)前項(xiàng)目中安裝的控件
二、全局引入模塊
在main.js 中引入
import Vue from 'vue'
import App from './App'
import router from './router'
import VueResouse from 'vue-resource' // 引入vue-resource
import MintUI from 'mint-ui' // 引入mint-ui
import 'mint-ui/lib/style.css' // 引入mint-ui的樣式
Vue.use(MintUI);
Vue.use(VueResouse);
Vue.config.productionTip = false
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})
三、開始構(gòu)建頁面框架
1、 將components(組件)文件夾下面的hello.vue 清空作為記賬頁面,并添加Count.vue作為統(tǒng)計(jì)頁面 如下:
<template>
<h1>記賬頁面</h1>
</template>
<template>
<h1>統(tǒng)計(jì)頁面</h1>
</template>
2、修改路由文件( router文件夾下面的index.js),加入我們剛才添加頁面的路由。
import Vue from 'vue'
import Router from 'vue-router'
import Hello from '@/components/Hello' // 記賬頁面
import Count from "@/components/Count" // 統(tǒng)計(jì)頁面
Vue.use(Router)
export default new Router({
routes: [
{path: '/',component: Hello},
{path: '/Count', component: Count}
]
})
3、修改App.vue
<template>
<div id="app">
<router-view class="Content"></router-view>
<mt-tabbar :fixed="true">
<router-link to="/" v-bind:class="ClassMenuHello" v-on:click.native="select(0)" > <i class="fa fa-edit"></i> 記賬 </router-link>
<router-link to="/Count" v-bind:class="ClassMenuCount" v-on:click.native="select(1)"> <i class="fa fa-bar-chart"></i> 統(tǒng)計(jì) </router-link>
</mt-tabbar>
</div>
</template>
<script>
export default {
name: 'app',
data(){
return{
selected:-1,
}
},
computed:{ // 使用計(jì)算屬性給菜單動(dòng)態(tài)添加樣式
ClassMenuHello(){
return{
'mint-tab-item':true,
'is-selected':this.selected==0,
}
},
ClassMenuCount(){
return{
'mint-tab-item':true,
'is-selected':this.selected==1,
}
}
},
methods:{
select(m){ // 給組件綁定事件時(shí)需要使用.native 例如綁定點(diǎn)擊事件使用 v-on:click.native="f"
this.selected=m;
},
}
}
</script>
<style scoped>
#app {
font-family: 'Avenir', Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
}
#app .mint-tab-item{
font-size: 20px;
padding: 15px;
}
#app .Content{
padding-bottom: 56px;
}
</style>
4、設(shè)置頁面禁止縮放,用于手機(jī)頁面。引入我們的圖標(biāo)庫。將index.html文件修改如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0" name="viewport" /> <!-- 禁止縮放,用于手機(jī)頁面-->
<title>易兒善-記賬</title>
<link rel="stylesheet"> <!-- 圖標(biāo)的樣式-->
</head>
<body>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
<style>
body,html {
margin: 0;
padding: 0;
}
</style>
四、查看效果
五、總結(jié)
1、使用 vue-router 中的 router-view 和 router-link 標(biāo)簽實(shí)現(xiàn)頁面間切換
2、使用computed 計(jì)算屬性動(dòng)態(tài)綁定樣式,實(shí)現(xiàn)選中樣式。
3、給組件標(biāo)簽綁定事件時(shí)需要使用.native 例如綁定點(diǎn)擊事件使用 v-on:click.native="f"
4、關(guān)于vue-router 和 mint-ui的更多用法參見官網(wǎng)
5、這樣編寫將頁面模塊化,而且一個(gè)頁面相關(guān)的js,style ,html都可以寫在一個(gè)頁面里。不同頁面分開寫。