网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

vue路由如何实现网站导航功能-创新互联

这篇文章给大家分享的是有关vue路由如何实现网站导航功能的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

创新互联是专业的海城网站建设公司,海城接单;提供网站制作、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行海城网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

1、首先需要按照Vue router支持

npm install vue-router
然后需要在项目中引入:

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

2、定义router的js文件

import Vue from 'vue'
import Router from 'vue-router'
import User from '../pages/user'
import Home from '../pages/public/home'
import Profile from '../pages/user/profile'
import Form from '../pages/form'
import Detail from '../pages/form/form'
import File from '../pages/form/file'
import Files from '../pages/file'

Vue.use(Router)

export default new Router({
 routes: [
  { path: '/', component:Home,
   children:[
    { path: '/user', component:Profile},
    { path: '/profile', component: User},
    { path: '/form', component: Form},
    { path: '/detail', component: Detail},
    { path: '/profiles', component: Files},
    { path: '/file', component: File}
   ]
  },

  { path: '/login', component:Login},
  { path: '/404', component:Error}
 ] 
})

3、在main.js中引入router

import router from './router'

new Vue({
 router,
 render: h => h(App),
}).$mount('#app')

4、入口页面定义router-view


 
 

5、在path指向为“/”的页面中,定义页面的布局,例如:上(头部)-中(左道航-右内容)-下(底部)。


 
       

6、左侧导航,用elementUI实现,有一个NavMenu导航菜单,做导航功能。

在这里提一下引入elementUI:

(1)安装

npm i element-ui -S

(2)使用

在main.js中加入下面的代码:

import ElementUI from 'element-ui';

  import 'element-ui/lib/theme-chalk/index.css';

  Vue.use(ElementUI);

导航栏的代码如下:


 
  
   
    
    {{ item.title }}
    
    
    
     {{ subItem.title }}
     
      {{ threeItem.title }}
     
    
    
     {{ subItem.title }}
    
    
   
  
  
   
    {{ item.title }}
   
  
 

定义左侧导航的显示和图标等内容,index为唯一标识,打开的是path路径,对应router中的path,就可以打开写好的相应的页面。

items: [
     {
      icon: 'el-icon-share',
      index: 'user',
      title: '系统首页'
     },
     {
      icon: 'el-icon-time',
      index: 'profile',
      title: '基础表格'
     },
     {
      icon: 'el-icon-bell',
      index: '3',
      title: '表单相关',
      subs: [
       {
        index: 'form',
        title: '基本表单'
       },
       {
        index: '3-2',
        title: '三级菜单',
        subs: [
         {
          index: 'detail',
          title: '富文本编辑器'
         },
         {
          index: 'file',
          title: 'markdown编辑器'
         },
        ]
       },
       {
        index: 'profiles',
        title: '文件上传'
       }
      ]
     },
    ]

7、如果涉及到登录页面和不需要路由的页面等,就需要在router的js文件中定义和“/”平级的其他path的页面,再判断进入页面是路由页面还是登录等页面。

感谢各位的阅读!关于“vue路由如何实现网站导航功能”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站题目:vue路由如何实现网站导航功能-创新互联
路径分享:http://bjjierui.cn/article/cdpjpg.html

其他资讯