美文网首页
Vue 路由设置title

Vue 路由设置title

作者: 两年半练习程序员 | 来源:发表于2018-12-17 17:10 被阅读0次

1.在index.js中为需要添加title的路由地址增加meta

// 引入Vue
import Vue from 'vue'
// 引入router
import Router from 'vue-router'
// 引入组件
import Index from '@/components/Index'
import Found from '@/components/Found'
import DataStock from '@/components/DataStock'
import My from '@/components/My'
//注明使用router
Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',//路由地址--根路径
      component: Index,
            meta: {
        title: '首页'
      }
    },
        {
            path:'/index.html',
            component:Index,
            meta: {
        title: '首页'
      }
        },
        {
            path:'/found.html',
            component:Found,
            meta: {
        title: '发现'
      }
        },
        {
            path:'/dataStock.html',
            component:DataStock,
            meta: {
        title: '资料库'
      }
        },
        ,
        {
            path:'/my.html',
            component:My,
            meta: {
        title: '我的'
      }
        }
  ],
    mode:'history'
})


2.在main.js中设置title

// 引入vue
import Vue from 'vue'
//引入模板
import App from './App'
//引入router
import router from './router'

//CSS
// import '../static/css/common.css'

Vue.config.productionTip = false

new Vue({
    el: '#app',
    router,
    template: '<App/>',//模板
    components: { App },//组件
    
 
})

router.beforeEach((to, from, next) => {
    document.title = to.meta.title
    next()
})
// index.html-->main.js-->App.vue(组件)

相关文章

  • Vue 路由设置title

    1.在index.js中为需要添加title的路由地址增加meta 2.在main.js中设置title

  • Vue 动态设置路由Meta title 名称

    路由配置 路由跳转 或路由配置 路由跳转 都可以,看着用。随堂笔记防遗忘!

  • Vue.js路由

    1.设置路由 ① 路由map 在main.js中导入vue-router 设置全局路由 实例化router ②路由...

  • Vue 基础 - 前端路由

    使用vue-router实现前端路由 安装vue-router: 配置路由文件,并在vue实例中导入: 设置视图(...

  • Vue 设置网页 title

    Vue 设置网页 title 方案1 方案2 vue-router-title 方案3 使用指令 1 2 3 vu...

  • vue-router学习总结

    1.引入vue-router npm install vue-router --save 2.设置路由(1)路由实...

  • vue-cli3 打包优化

    1、设置路由懒加载 importVuefrom'vue'importRouterfrom'vue-router'V...

  • vue动态title

    我的解决方式利用vue-router的meta属性加上vue的路由守卫beforeEach配置动态title ro...

  • vue-router @4.x 和 @3.x 对比

    1. 创建实例 2. 路由重定向 vue2.x使用路由选项redirect设置路由自动调整,vue3.x中移除了这...

  • vue路由设置

    关于vue的安装前面也已经介绍了这里就不介绍了,今天主要介绍路由的设置,下面来一一分析一下 安装路由及配置 插件安...

网友评论

      本文标题:Vue 路由设置title

      本文链接:https://www.haomeiwen.com/subject/aquckqtx.html