1.頁面骨架開發
1.1組件拆分
手機瀏覽器是把頁面放在一個虛擬的“窗口”(viewport)中,通常這個虛擬的“窗口”(viewport)比屏幕寬,這樣就不用把每個網頁擠到很小的窗口中(這樣會破壞沒有針對手機瀏覽器優化的網頁的布局),用戶可以通過平移和縮放來看網頁的不同部分。
<meta name="viewport" content="width=device-width,inital-scale=1.0, maximum-scale=1.0,user-scalable=no">
參考:http://www.runoob.com/css/css-rwd-viewport.html
1.2header組件的導出、導入和引用
header.vue中 export default{}
App.vue中 import header from './components/header/header.vue'; export default{ components: { 'v-header': header }} 就可以在template中引用 <v-header></v-header>
1.3 移動端經典布局-flex布局
1.4移動端中所有的寬度高度都是按兩倍大小設計,設計圖中的80px,在css中應設置為40px;
1.5 vue-loader依賴postcss插件,該插件會自動幫助我們完成瀏覽器兼容性的寫法。
1.6 vue-router
main.js中
import VueRouter from 'vue-router';
// 安裝 "VueRouter"這個插件 Vue.use(VueRouter);
App.vue template中:
<!-- 使用 router-link 組件來導航. -->
<!-- 通過傳入 `to` 屬性指定鏈接. -->
<!-- <router-link> 默認會被渲染成一個 `<a>` 標簽 -->
<router-link to="/foo">Go to Foo</router-link>
<router-link to="/bar">Go to Bar</router-link>
</p>
<!-- 路由出口 -->
<!-- 路由匹配到的組件將渲染在這里 -->
<router-view></router-view>
該項目中
<div class="tab-item"> <router-link v-bind:to="'/goods'"> 在CSS中要對a標簽進行樣式編寫 商品 </router-link> </div> <router-view ></router-view>
main.js中JavaScript寫法
vue文檔
// 0. 如果使用模塊化機制編程,導入Vue和VueRouter,要調用 Vue.use(VueRouter) // 1. 定義(路由)組件。 // 可以從其他文件 import 進來 const Foo = { template: '<div>foo</div>' } const Bar = { template: '<div>bar</div>' } // 2. 定義路由 // 每個路由應該映射一個組件。 其中"component" 可以是 // 通過 Vue.extend() 創建的組件構造器, // 或者,只是一個組件配置對象。 // 我們晚點再討論嵌套路由。 const routes = [ { path: '/foo', component: Foo }, { path: '/bar', component: Bar } ] // 3. 創建 router 實例,然后傳 `routes` 配置 // 你還可以傳別的配置參數, 不過先這么簡單着吧。 const router = new VueRouter({ routes // (縮寫)相當於 routes: routes }) // 4. 創建和掛載根實例。 // 記得要通過 router 配置參數注入路由, // 從而讓整個應用都有路由功能 const app = new Vue({ router }).$mount('#app') // 現在,應用已經啟動了!
提供一個在頁面上已存在的 DOM 元素作為 Vue 實例的掛載目標。可以是 CSS 選擇器,也可以是一個 HTMLElement 實例。在實例掛載之后, 元素可以用 vm.$el
訪問。如果這個選項在實例化時有作用,實例將立即進入編譯過程,否則,需要顯式調用 vm.$mount()
手動開啟編譯。
對應到該項目中,寫法為:
// The Vue build version to load with the `import` command // (runtime-only or standalone) has been set in webpack.base.conf with an alias. import Vue from 'vue'; import VueRouter from 'vue-router'; import VueResource from 'vue-resource'; import App from './App'; import goods from './components/goods/goods.vue'; import ratings from './components/ratings/ratings.vue'; import seller from './components/seller/seller.vue'; import 'common/stylus/index.styl'; // 安裝 "VueRouter"這個插件 /* eslint-disable no-new */ Vue.use(VueRouter); Vue.use(VueResource);
//路由配置 let routes = [ {path: '/', name: 'index', component: App, children: [{path: '/goods', component: goods}, {path: '/ratings', component: ratings}, {path: '/seller', component: seller}]} ]; let router = new VueRouter({ 'linkActiveClass': 'active', routes // (縮寫)相當於 routes: routes }); let app = new Vue({ router }).$mount('#app');
//一進入就顯示goods組件 router.push('/goods'); export default app;
導航高亮的實現,通過Router 構造配置linkActiveClass,linkActiveClass它默認值為"router-link-active"(也就是對應的class名為router-link-active),這里我們覆蓋它的默認值,'linkActiveClass': 'active' 將其改為了active,在寫css時,我們用的就是這個active。
1.7 導航欄中1像素邊框
pc端的1像素在手機中會顯示2像素,采用after偽類
mixin.styl中
border-1px($color) position : relative &:after display: block position: absolute left: 0 bottom: 0 border-top 1px solid $color width: 100% content: ''
@media (-webkit-min-device-pixel-ratio: 1.5),(min-device-aspect-ratio: 1.5) .border-1px //div中設置該類 &::after -webkit-transform : scaleY(0.7)//1.5*0.7約為1 transform : scaleY(0.7)//Y軸縮放 @media (-webkit-min-device-pixel-ratio: 2),(min-device-aspect-ratio: 2) .border-1px &::after -webkit-transform : scaleY(0.5) transform : scaleY(0.5)
使用 @media 查詢,你可以針對不同的媒體類型定義不同的樣式。@media 可以針對不同的屏幕尺寸設置不同的樣式,特別是如果你需要設置設計響應式的頁面,@media 是非常有用的。當你重置瀏覽器大小的過程中,頁面也會根據瀏覽器的寬度和高度重新渲染頁面。同理,上邊框可以用before實現;
1.8 mixin.styl的作用,里面可以寫函數(是全局樣式),可以在多處引用(引入:@import "common/stylus/mixin.styl"; )
1.9通過手機訪問,通過ipconfig查看本機ip為192.168.0.1,用這個ip替換url中的localhost
將替換后的地址通過草料網站(http://cli.im/),生成對應的二維碼,手機和電腦連接同一局域網時,就可在手機掃碼查看頁面了。