• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

vue 搞代码 4年前 (2022-01-08) 24次浏览 已收录 0个评论

这篇文章主要为大家详细介绍了Vue.js路由实现选项卡简单实例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了Vue.js路由实现选项卡的具体代码,供大家参考,具体内容如下

需要实现下图效果,点击上方选项卡,切换到不同内容的组件:

事先准备好两个库文件(vue.js、vue-router.js),放到对应路径。

1.引入依赖库

 

2.组件创建

 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.' } } }); const Javascript = Vue.extend({ template: '<div><h1>Javascript</h1><p>{{msg}}</p></div>', data(){ return{ msg: 'This is the Javascript vue-router.' } } });

3.路由创建与映射

 const router =<i style="color:transparent">本文来源gaodai$ma#com搞$代*码6网</i> new VueRouter({ routes: [ { path: '/html', component: Html }, { path: '/css', component: Css }, { path: '/vue', component: Vue1 }, { path: '/javascript', component: Javascript }, { path: '/', component: Html } //默认路径 ] });

4.挂在实例

 const vm = new Vue({ router: router }).$mount('#app'); 

5.页面,to指令跳转到指定路径

 <div id="app"> <div class="app-tit"> htmlcssvuejavascript</div><div class="app-con"> </div></div>

6.所用样式

  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; } 

完整代码

   <title>hello world</title> 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; }  <div id="app"> <div class="app-tit"> htmlcssvuejavascript</div><div class="app-con"> </div></div>

如有错误之处,欢迎指出,万分感谢!

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持gaodaima搞代码网

以上就是Vue.js路由实现选项卡简单实例的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Vue.js路由实现选项卡简单实例

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址