vue2.0 仿手机新闻站(二)项目结构搭建 及 路由配置
2017-09-21 19:30
871 查看
1.项目结构
2.main.js
3.入口文件 App.vue
4.组件部分 components
(1)Nav.vue
(2)Footer.vue
(3)Home.vue 首页
(4)Follow.vue 关注页
(5)Column.vue 栏目页
(6)UserInfo.vue 我的页
5.路由配置文件 router.config.js
6.效果图
$ vue init webpack-simple news
$ npm install vuex vue-router axios style-loader css-loader -D
2.main.js
import Vue from 'vue' import App from './App.vue' // 引入 路由 import VueRouter from 'vue-router' // 引入 路由配置文件 import routes from './router.config' Vue.use(VueRouter); // 创建 路由 const router = new VueRouter({ mode:'history', // 删除 url 中的'#'号 routes // routes 等价于 routes:routes }); require('./assets/css/base.css'); // 全局引入 new Vue({ el: '#app', router, render: h => h(App) })
3.入口文件 App.vue
<template> <div id="app"> <NavView></NavView> <router-view></router-view> <FooterView></FooterView> </div> </template> <script> /** * 引入 组件 */ // 头部导航 import NavView from './components/Nav.vue' // 中间内容 import HomeView from './components/Home.vue' // 底部选项卡 import FooterView from './components/Footer.vue' export default { components:{ NavView, FooterView } } </script> <style lang="scss"> @import './assets/css/index.css'; </style>
4.组件部分 components
(1)Nav.vue
<!-- 顶部选项卡 --> <template> <div id="nav"> <div class="nav"> <ul> <router-link to="/home" tag="li" active-class="active"> <a href="javascript:;">首页</a> </router-link> <router-link to="/follow" tag="li" active-class="active"> <a href="javascript:;">关注</a> </router-link> <router-link to="/column" tag="li" active-class="active"> <a href="javascript:;">栏目</a> </router-link> </ul> </div> </div> </template>
(2)Footer.vue
<!-- 底部选项卡 --> <template> <div class="foot-btn"> <ul> <!--首页--> <router-link class="home" to="/home" tag="li"> <a href="javascript:;"></a> </router-link> <!--关注--> <router-link class="write" to="/follow" tag="li"> <a href="javascript:;"></a> </router-link> <!--我的--> <router-link class="my" to="/user-info" tag="li"> <a href="javascript:;"></a> </router-link> </ul> </div> </template>
(3)Home.vue 首页
<!-- 首页 --> <template> <div id="home"> <div class="content mt30">首页部分</div> </div> </template> <script> export default{ } </script> <style scoped> .mt30{ margin-top: 30px; } </style>
(4)Follow.vue 关注页
<!-- 关注页 --> <template> <div id="follow"> <div class="content mt30">关注部分</div> </div> </template> <style scoped> .mt30{ margin-top: 30px; } </style>
(5)Column.vue 栏目页
<!-- 栏目页 --> <template> <div id="column"> <div class="content mt30">栏目部分</div> </div> </template> <style scoped> .mt30{ margin-top: 30px; } </style>
(6)UserInfo.vue 我的页
<!-- 我的 --> <template> <div class="content"> <div class="header"> <h2><img src="../assets/img/headimg.png" alt=""/></h2> <div class="user-box"> <router-link to="/user-login">登录</router-link> <router-link to="/user-reg">注册</router-link> </div> <ul class="clear"> <li> <span>0</span> <p>关注</p> </li> <li> <span>0</span> <p class="end">粉丝</p> </li> </ul> </div> <div class="docList"> <ul> <li class="gk-text"> <i></i> <p>公开博文</p> <b></b> <span>0</span> </li> <li class="mm-text"> <i></i> <p>秘密博文</p> <b></b> <span>0</span> </li> <li class="cg-text"> <i></i> <p>草稿箱</p> <b></b> <span>0</span> </li> <li class="sc-text"> <i></i> <p>收藏夹</p> <b></b> <span>0</span> </li> <li class="my_cz"> <i></i> <p>收藏夹</p> </li> </ul> </div> </div> </template> <style scoped> @import '../assets/css/mydoc.css'; </style>
5.路由配置文件 router.config.js
/** * 配置 路由 */ // 导入组件 import Home from './components/Home.vue' import Follow from './components/Follow.vue' import Column from './components/Column.vue' import UserInfo from './components/UserInfo.vue' // 导出路由数组 export default [ { // 首页 path:'/home', component:Home }, { // 关注页 path:'/follow', component:Follow }, { // 栏目页 path:'/column', component:Column }, { // 我的页 path:'/user-info', component:UserInfo }, { // 配置默认路由 path:'/', redirect:'/home' // 路由重定向 }, { path:'*', redirect:'/home' // 路由重定向 } ]
6.效果图
相关文章推荐
- Vue2项目架构搭建(八)—— vue-router2路由配置和调用
- vue2.0 仿手机新闻站(一)项目开发流程
- 使用Vue-cli搭建多页面应用时对项目结构和配置的调整
- vuex 项目结构目录及一些简单配置介绍
- 快速搭建vue2.0+boostrap项目的方法
- 从壹开始前后端分离【 .NET Core2.0 Api + Vue 2.0 + AOP + 分布式】框架之七 || API项目整体搭建 6.2 轻量级ORM
- 【vue2.0实战分享】搭建vue运行环境以及项目目录
- vue2.0实战之使用vue-cli搭建项目(2)
- 从壹开始前后端分离【 .NET Core2.0 Api + Vue 2.0 + AOP + 分布式】框架之六 || API项目整体搭建 6.1 仓储
- 【vue-cli】vue-cli+webpack配置下局域网,手机无法访问绑定ip的vue项目
- vue2.0 仿手机新闻站(五)全局的 loading 组件
- vue2.0项目实战(2)使用 vue-cli 搭建项目
- vue-cli#2.0项目结构分析
- vue2.0 项目搭建 和vue 2.0 electron 项目搭建
- vue2.0新手填坑攻略之使用vue-cli搭建vue项目开发环境到项目发布
- JAVAWEB开发之Maven的入门详解——Maven的安装以及项目的结构和Maven的使用以及私服的搭建与配置
- vue2.0 + vux 项目搭建
- JAVAWEB开发之Maven的入门详解——Maven的安装以及项目的结构和Maven的使用以及私服的搭建与配置
- 用vue-router和webpack搭建路由项目
- Ionic 入门与实战之第三章:Ionic 项目结构以及路由配置