Vue.js路由实现选项卡简单实例

2020-06-14 06:31:00易采站长站整理

}
#app{
width: 600px;
margin: 0 auto;
}
.app-tit{
font-size: 0;
width: 600px;
}
.app-tit .router-link-active {
background: #09f;
color: #fff;
}
.app-tit a{
display: inline-block;
height: 40px;
line-height: 40px;
font-size: 16px;
width: 25%;
text-align: center;
background: #ccc;
color: #333;
text-decoration: none;
}
.app-con div{
border: 1px solid #ccc;
height: 400px;
padding-top: 20px;
}

</style>

完整代码


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="GBK">
<title>hello world</title>
<script src="vue.js" type="text/javascript" charset="GBK"></script>
<script src="vue-router.js" type="text/javascript" charset="GBK"></script>
</head>
<style>
body{
font-family:"Microsoft YaHei";
}
#app{
width: 600px;
margin: 0 auto;
}
.app-tit{
font-size: 0;
width: 600px;
}
.app-tit .router-link-active {
background: #09f;
color: #fff;
}
.app-tit a{
display: inline-block;
height: 40px;
line-height: 40px;
font-size: 16px;
width: 25%;
text-align: center;
background: #ccc;
color: #333;
text-decoration: none;
}
.app-con div{
border: 1px solid #ccc;
height: 400px;
padding-top: 20px;
}

</style>
<body>
<div id="app">
<div class="app-tit">
<router-link to="/html">html</router-link>
<router-link to="/css">css</router-link>
<router-link to="/vue">vue</router-link>
<router-link to="/javascript">javascript</router-link>
</div>
<div class="app-con">
<router-view></router-view>
</div>
</div>

<script type="text/javascript">
const Html = Vue.extend({
template: '<div><h1>html</h1><p>{{msg}}</p></div>',
data: function() {
return {
msg: 'This is the html vue-router.'
}
}
});
const Css = Vue.extend({
template: '<div><h1>CSS</h1><p>{{msg}}</p></div>',
data(){
return{
msg: 'This is the CSS vue-router.'
}
}
});
const Vue1 = Vue.extend({
template: '<div><h1>Vue</h1><p>{{msg}}</p></div>',
data(){
return{
msg: 'This is the Vue vue-router.'