$ vue create myApp $ cd app $ npm run serve
首先須要對項目的頁面結構有個大體規劃。以個人項目爲例css
- '/money': money頁面(默認進入money頁面) - '/labels': labels頁面 - '/statistics': statistics頁面 - 404頁面
進入router文件夾的index.ts文件下修改路由配置,並在views文件夾內建立對應的.vue
組件vue
const routes = [{ //訪問根目錄 直接重定向到money頁面 path: '/', redirect:'money' },{ path: '/money', component: Money },{ path: '/labels', component: Labels },{ path: '/statistics', component: Statistics },{ path: '*', component: NotFound }]
在App.vue的template模板內寫入<router-view/>
標籤,這樣Vue Router就會根據訪問路徑不一樣去切換顯示頁面了。git
底部導航欄<Nav/>組件的引入形式github
分別放在每一個頁面中
1) 全局引入typescript
//App.vue import Nav from "@/components/Nav.vue" Vue.component('Nav',Nav)
2) 局部引入 代碼冗餘npm
[踩坑]底部導航欄的佈局方式app
flex佈局:推薦。
實現方式:svg
.container{ display:flex; flex-direction:column; height: 100vh; } .content{ flex-grow:1; //實現內容的鋪滿 overflow: auto; }
props
和<slot>
插槽搞定[踩坑] 使用 svg-sprite-loader
引入 icon
1) 沒法在 TypeScript 中引入 SVG 文件
學自 StackOverflow 點擊查看模塊化
//shims-vue.d.ts declare module "*.svg" { const content: string; export default content; }
2) 配置 SVG sprite loader組件化
[踩坑] 如何引入整個 icons 文件夾裏的 .svg文件(一樣適用於其餘後綴)
let importAll = (requireContext:__WebpackModuleApi.RequireContext) => requireContext.keys().forEach(requireContext); importAll(require.context("../assets/icons", true, /\.svg$/));
路由激活 active-class
<router-link to="/labels" active-class="selected"> ...
選中激活時,加上selected類
CSS的規劃
padding,margin,box-sizing ...
變量:多處用到的樣式,能夠新建一個scss文件,以變量形式保存,用到的地方直接引入。例如:
//style.scss $color-active: red //cpn.vue .active{ color:$color-active; }
<style scoped>...</style>
TS實現
第一個TS組件
import { Component } from "vue-property-decorator";
使用Component裝飾器
@Component export default class Type extends Vue { number = 0; //被裝飾器放在data裏 add(n: Number) { //被裝飾器放在methods裏 this.number += n; } }
未完待續