1.页面骨架开发
1.1组件拆分
手机浏览器是把页面放在一个虚拟的“窗口”(viewport)中,通常这个虚拟的“窗口”(viewport)比屏幕宽,这样就不用把每个网页挤到很小的窗口中(这样会破坏没有针对手机浏览器优化的网页的布局),用户可以通过平移和缩放来看网页的不同部分。
参考:
1.2header组件的导出、导入和引用
header.vue中export default{}
App.vue中import header from './components/header/header.vue';export default{ components: { 'v-header': header }} 就可以在template中引用
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中:
Go to Foo Go to Bar
该项目中
在CSS中要对a标签进行样式编写 商品
main.js中JavaScript写法
vue文档
// 0. 如果使用模块化机制编程,導入Vue和VueRouter,要调用 Vue.use(VueRouter)// 1. 定义(路由)组件。// 可以从其他文件 import 进来const Foo = { template: 'foo' }const Bar = { template: 'bar' }// 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
将替换后的地址通过草料网站(),生成对应的二维码,手机和电脑连接同一局域网时,就可在手机扫码查看页面了。