vue2.0 仿手机新闻站(二)项目结构搭建 及 路由配置
1.项目结构
$ 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.0 仿手机新闻站(二)项目结构搭建 及 路由配置的更多相关文章
- vue2.0 仿手机新闻站(一)项目开发流程
vue仿手机新闻站: 1.拿到静态页面,直接用vue边布局,边写 2.假数据 没有用任何UI组件,切图完成 做项目基本流程: 1.规划组件结构 Nav.vue Header.vue Home.vue ...
- vue2.0 仿手机新闻站(七)过滤器、动画效果
1.全局过滤器 (1)normalTime.js 自定义 将 时间戳 转换成 日期格式 过滤器 /** * 将 时间戳 转换成 日期格式 */ export const normalTime = ( ...
- vue2.0 仿手机新闻站(六)详情页制作
1.结构 2.配置详情页路由 router.config.js /** * 配置 路由 */ // 导入组件 import Home from './components/Home.vue' impo ...
- vue2.0 仿手机新闻站(五)全局的 loading 组件
1.组件结构 index.js const LoadingComponent = require('./Loading.vue') const loading = { install: functio ...
- vue2.0 仿手机新闻站(四)axios
1.axios的配置 main.js import Vue from 'vue' import App from './App.vue' // 引入 路由 import VueRouter from ...
- vue2.0 仿手机新闻站(三)通过 vuex 进行状态管理
1.创建 store 结构 2.main.js 引入 vuex 3. App.vue 组件使用 vuex <template> <div id="app"&g ...
- 项目vue2.0仿外卖APP(二)
vue-cli开启vue.js项目 github地址:https://github.com/vuejs/vue-cli Vue.js开发利器vue-cli,是vue的脚手架工具. 在工地上,脚手架是工 ...
- 本地运行github上的vue2.0仿饿了么webapp项目
在vue刚刚开始流行的时候,大多数人学习大概都见到过这样的一个项目吧,可以作为学习此框架的一个模板了 github源码地址:https://github.com/RegToss/Vue-SPA 课程教 ...
- Vue2.0仿饿了么webapp单页面应用
Vue2.0仿饿了么webapp单页面应用 声明: 代码源于 黄轶老师在慕课网上的教学视频,我自己用vue2.0重写了该项目,喜欢的同学可以去支持老师的课程:http://coding.imooc.c ...
随机推荐
- github 客户端总是登录失败,提示密码错误
把输入法调成英文即可!!
- BZOJ 2190:[SDOI2008]仪仗队(欧拉函数)
[SDOI2008]仪仗队 Description 作为体育委员,C君负责这次运动会仪仗队的训练.仪仗队是由学生组成的N * N的方阵,为了保证队伍在行进中整齐划一,C君会跟在仪仗队的左后方,根据其视 ...
- Normalize.css用法
1 Normalize.css用法 重置样式非常多,Normalize.css和reset是两个常用的重置 CSS 文件 http://necolas.github.io/normalize.css/ ...
- 所驼门王的宝藏(bzoj 1924)
Description Input 第一行给出三个正整数 N, R, C. 以下 N 行,每行给出一扇传送门的信息,包含三个正整数xi, yi, Ti,表示该传送门设在位于第 xi行第yi列的藏宝宫室 ...
- Codevs 1085 数字游戏
1085 数字游戏 2003年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 丁丁最近沉迷于一个数字游戏之中 ...
- [LeetCode] Scramble String 字符串 dp
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- Codeforces Gym101502 E.The Architect Omar-find()函数
E. The Architect Omar time limit per test 1.0 s memory limit per test 256 MB input standard input ...
- C++ primer分章节快速回顾
第三章: 1,sozeof(int): int n_int=INT_MAX; sizeof n_int;(对变量括号可选) 2,#include<climits>包含一些类型的最大值3,c ...
- 4C 2018 福到了
输入字符c(只含有@和空格).数字n.规模n*n的二维字符矩阵. 若倒过来的数组和原数组一样形式输出提示. 最后输出以字符c替换的字符数组. #include <bits/stdc++.h> ...
- Codeforces 903F Clear The Matrix(状态压缩DP)
题目链接 Clear The Matrix 题意 给定一个$4 * n$的矩形,里面的元素为$'.'$或$'*'$.现在有$4$种正方形可以覆盖掉$'*'$,正方形的边长分别为$1,2,3,4$. 求 ...