-node-modules 依賴文件 -public 基本文件,包含頁面,圖片,小圖標 -src 項目主場 -tests 測試 .editorconfig 編輯器配置文件 .gitignore git忽略文件 babel.config.js babel配置文件 cypress.json 插件 package.json 描述文件
-assets 靜態資源文件 -components 自定義的組件 -router 路由文件 -store 狀態管理器 -views 頁面㢟 App.vue 入口頁面結構 main.js 入口文件
cnpm run servecss
.vue 文件 --- vue的單文件組件,內含組件的結構、組件的邏輯、組件的樣式html
<template> <div class="container"> <div class="box"> <header class="header">頭部</header> <div class="content">內容</div> </div> <footer class="footer">底部</footer> </div> </template>
<style lang="scss"> @import '@/lib/reset.scss'; // 引入重置樣式,@表示的就是src目錄 html, body, .container { @include rect(100%, 100%); // width: 100%;height: 100%; } .container { // 建議使用彈性盒佈局 @include flexbox(); // display: -webkit-box;display: -ms-flexbox;display: flex; @include flex-direction(column); // -webkit-box-orient: vertical;-webkit-box-direction: normal;-ms-flex-direction: column;flex-direction: column; .box { @include flex(); // -webkit-box-flex: 1;-ms-flex: 1;flex: 1;width: .1px; @include rect(100%, auto); @include flexbox(); @include flex-direction(column); .header { @include rect(100%, 0.44rem); @include background-color(#f66); } .content { @include flex(); @include rect(100%, auto); @include overflow(); // overflow: auto;-webkit-overflow-scrolling: touch; } } .footer { @include rect(100%, 0.5rem); @include background-color(#efefef); } } </style>
<footer class="footer"> <ul> <li> <span></span> <p>首頁</p> </li> <li> <span></span> <p>分類</p> </li> <li> <span></span> <p>購物車</p> </li> <li> <span></span> <p>個人</p> </li> </ul> </footer> .footer { @include rect(100%, 0.5rem); @include background-color(#efefef); ul { @include rect(100%, 100%); @include flexbox(); li{ @include flex(); @include rect(auto, 100%); @include flexbox(); // 一下幾句實現的是元素的水平垂直居中 @include flex-direction(column); @include justify-content(); // -webkit-box-pack: center;-ms-flex-pack: center;justify-content: center; @include align-items(); // -webkit-box-align: center; -ms-flex-align: center; align-items: center; } } }
地址輸入欄不一樣,顯示不一樣的頁面vue
以 home/index.vue 爲例,複製App.vue文件中的 頭部和內容區域的代碼node
<template> <div class="box"> <header class="header">首頁頭部</header> <div class="content">首頁內容</div> </div> </template>
const routes = [ { // 路由跟組件時映射關係 path: '/home', name: 'home', // 路由的懶加載 component: () => import('@/views/home/index.vue') }, { path: '/kind', name: 'kind', component: () => import('@/views/kind/index.vue') }, { path: '/cart', name: 'cart', component: () => import('@/views/cart/index.vue') }, { path: '/user', name: 'user', component: () => import('@/views/user/index.vue') } ]
<!-- <div class="box"> <header class="header">頭部</header> <div class="content">內容</div> </div> --> <router-view></router-view>
router-view 若是路由是 /home,此處就爲首頁的組件
瀏覽器輸入 /home /kind /cart /user 查看效果ios
const routes = [ { // 開始添加劇定向 path: '/', redirect: '/home' }, { // 路由跟組件時映射關係 path: '/home', name: 'home', // 路由的懶加載 component: () => import('@/views/home/index.vue') }, .... ]
<footer class="footer"> <ul> <router-link to="/home" tag="li"> <span></span> <p>首頁</p> </router-link> <router-link to="/kind" tag="li"> <span></span> <p>分類</p> </router-link> <router-link to="/cart" tag="li"> <span></span> <p>購物車</p> </router-link> <router-link to="/user" tag="li"> <span></span> <p>個人</p> </router-link> </ul> </footer>
li{ @include flex(); @include rect(auto, 100%); @include flexbox(); // 一下幾句實現的是元素的水平垂直居中 @include flex-direction(column); @include justify-content(); // -webkit-box-pack: center;-ms-flex-pack: center;justify-content: center; @include align-items(); // -webkit-box-align: center; -ms-flex-align: center; align-items: center; &.router-link-active { // 審查元素得知選中的樣式 @include color(#f66); } }
http://iconfont.cn/git
<title>myapp</title> <link rel="stylesheet" href="//at.alicdn.com/t/font_1476238_m5fuchmwska.css">
在 App.vue 中添加圖標es6
<footer class="footer"> <ul> <router-link to="/home" tag="li"> <span class="iconfont icon-fonts-shouye"></span> <p>首頁</p> </router-link> <router-link to="/kind" tag="li"> <span class="iconfont icon-icon"></span> <p>分類</p> </router-link> <router-link to="/cart" tag="li"> <span class="iconfont icon-gouwuche"></span> <p>購物車</p> </router-link> <router-link to="/user" tag="li"> <span class="iconfont icon-wode"></span> <p>個人</p> </router-link> </ul> </footer>
li{ @include flex(); @include rect(auto, 100%); @include flexbox(); // 一下幾句實現的是元素的水平垂直居中 @include flex-direction(column); @include justify-content(); // -webkit-box-pack: center;-ms-flex-pack: center;justify-content: center; @include align-items(); // -webkit-box-align: center; -ms-flex-align: center; align-items: center; &.router-link-active { @include color(#f66); } span { @include font-size(0.24rem); } p { @include font-size(0.12rem); @include margin(-5px 0 0); } }
可能多出會使用到,建議封裝爲 組件web
<template> <ul class="prolist"> <li class="proitem"> <div class="itemimg"> <img src="" alt=""> </div> <div class="iteminfo"> <h2>標題</h2> </div> </li> </ul> </template>
es6的模塊化npm
暴露 export default {}
引入 import MO from './sss'json
<template> <div class="box"> <header class="header">首頁頭部</header> <div class="content"> <!-- 使用組件 --> <Prolist /> </div> </div> </template> <script> // 引入列表的組件 ---- es6中的模塊化 import Prolist from '@/components/Prolist.vue' export default { // 註冊組件 components: { // Prolist: Prolist Prolist } } </script>
<style lang="scss"> @import '@/lib/reset.scss'; .prolist { @include rect(100%, auto); .proitem { @include rect(100%, 1rem); @include border(0 0 1px 0, #efefef, solid); // 設定的是一個物理像素 @include flexbox(); .itemimg { @include rect(1rem, 1rem); img { @include rect(0.9rem, 0.9rem); @include border(1px, #f66, solid); @include margin(0.05rem); @include display(block); } } .iteminfo { @include flex(); } } } </style>
cnpm i axios -S
<script> import axios from 'axios' // 引入列表的組件 ---- es6中的模塊化 import Prolist from '@/components/Prolist.vue' export default { // 註冊組件 components: { // Prolist: Prolist Prolist }, data () { return { prolist: [] } }, created () { axios.get('https://47.103.82.2/douban').then(res => { this.prolist = res.data }) } } </script> <Prolist :prolist="prolist"/>
Prolist.vue 接收數據而且渲染
<template> <ul class="prolist"> <li class="proitem" v-for="item of prolist" :key="item.id"> <div class="itemimg"> <img :src="item.images.small" alt=""> </div> <div class="iteminfo"> <h2>{{ item.title }}</h2> </div> </li> </ul> </template> <script> export default { props: ['prolist'] } </script>
public/index.html 添加meta標籤
<meta name="referrer" content="no-referrer">