一个vue的单页应用(一级路由)的脚手架程序构建
1.进入某个目录如D:\VueStudy
2.通过命令创建项目:vue init webpack vue-router-demol(后几项都选N)
3.cd进入vue-router-demo1目录
4.安装依赖:npm install
5.运行:npm run dev
6.更改config目录下的index。js文件,将端口改成80
7.进行一级路由配置
App.vue
router文件的index.js文件
新建
1.Index.vue(components中)
2.Message.vue(components中)
修改index和APP.vue
APP.vue类
<template>
<div id="app" class="container">
<div class="header">
<router-link to="/" class="nav-item">首页</router-link>
<router-link to="/message" class="nav-item">消息</router-link>
</div>
<div class="content">
<router-view></router-view>
</div>
</div>
</template>
<script>
export default {
name: 'App'
}
</script>
<style>
.container{
width: 80%;
margin: 0 auto;
height: 400px;
}
.header{
display: flex;
height: 100px;
background-color: darkcyan;
font-size: 20px;
padding-left: 20px;
align-items: center;
}
.nav-item{
margin-right: 20px;
}
.content{
background-color: #2c3e50;
color: #ffffff;
}
</style>
Index.vue类
<template>
<div class="container">
<h2>首页</h2>
{{msg}}
</div>
</template>
<script>
export default{
name:'Index',
data(){
return{
msg:'首页'
};
}
};
</script>
<style scoped>
</style>
Message类
<template>
<div class="container">
<h2>消息</h2>
{{ msg }}
</div>
</template>
<script>
export default {
name: 'Index',
data() {
return {
msg: '消息'
};
}
};
</script>
<style scoped></style>
index.vue类
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export default new Router({
mode:"history",
//使上面的/后面没有#号如:
routes: [
{
path: '/',
name: 'Index',
component: resolve=>require(['../components/Index.vue'],resolve)
},
{
path: '/message',
name: 'Message',
component: resolve=>require(['../components/Message.vue'],resolve)
},
]
})
运行结果:
image image可以调首页和消息的颜色,没有下划线,并且点的时候有颜色
a {
text-decoration: none;
color: antiquewhite;
}a:hover{
text-decoration: none;
color: #2C3E50
}
网友评论