要模仿的界面以下:css
在static中新增css/reset.css,样式参考:https://github.com/lwl0812/vue-sell/tree/master/static/csshtml
在index.html中引入reset.cssvue
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
<template> <div id="app"> <div class="header"> I am header. </div> <header></header> <div class="tab"> I am tab. </div> <div class="content"> I am content. </div> </div> </template> <script> export defaut {}; </script> <style> </style>
在 components 下新建 header/header.vue,内容以下:git
<template> <div class="header"> 我是header </div> </template> <script> export default {}; </script> <style lang="stylus" rel="stylesheet/stylus"> </style>
编译stylus时会报错,能够安装下stylus,而后重启es6
npm install stylus --save-dev
npm run dev
引用header组件github
// App.vue
<script> import header from './components/header/header'; export default { components: { 'v-header': header // 此处header与原生html名字相同,因此须要重命名,按es6的语法写的话,只要写header便可,具体参看es6语法 } }; </script>
使用header组件vue-router
// App.vue <template> <div id="app"> <v-header></v-header> <!--使用header组件--> <div class="tab"> I am tab. </div> <div class="content"> I am content. </div> </div> </template>
此时,界面以下:npm
// App.vue <template> <div id="app"> <v-header></v-header> <div class="tab"> <!--tab 内容--> <div class="tab-item">商品</div> <div class="tab-item">评论</div> <div class="tab-item">商家</div> </div> <div class="content"> I am content. </div> </div> </template>
// App.vue <style lang="stylus" rel="stylesheet/stylus"> .tab display: flex width: 100% height: 40px line-height: 40px .tab-item flex: 1 text-align: center </style>
样式使用了flex布局,可参考阮一峰老师的语法篇和实例篇:app
http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html布局
http://www.ruanyifeng.com/blog/2015/07/flex-examples.html
此时,界面以下:
这一节完成,下一节学习vue-router