【问题标题】:Vue Router not displaying templateVue路由器不显示模板
【发布时间】:2020-05-24 13:57:23
【问题描述】:

我正在尝试让 Vue 路由器在我的 Vue 应用程序中工作。当我单击链接时,它只是重新加载页面并且不显示仪表板模板。有关如何解决此问题的任何想法?

这是我的 main.js 文件中的内容:

import Vue from 'vue'
import App from './App.vue'
import VModal from 'vue-js-modal'
import TreeView from "vue-json-tree-view"
import '@/assets/css/tailwind.css'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import store from './store.js'

Vue.use(VueRouter)
Vue.use(Vuex)
Vue.config.productionTip = false
Vue.use(VModal)
Vue.use(TreeView)



let Dashboard = require('./components/Dashboard.vue');
let Home = require('./components/LandingPage.vue');



const routes = [{
  path: '/',
  component: Home
},
{
  path: '/dasboard',
  name: Dashboard,
  component: Dashboard
}
];

const router = new VueRouter
({
    mode: 'history',
    routes
})

Vue.use(VueRouter)

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

在我的 LandingPage.vue 文件中,我有这个链接:

<router-link to="/dashboard">Dashboard</router-link>

我的 Dashboard.vue 文件是一个简单的模板:

<template>
  <div>
    <h1>Dashboard</h1>
  </div>
</template>

<script>
export default {

}
</script>

<style>

</style>

谢谢

【问题讨论】:

    标签: vue.js vue-router


    【解决方案1】:

    你的路线应该这样定义

    const routes = [{
      path: '/',
      component: Home
    },
    {
      path: '/dashboard',
      name: 'dashboard',
      component: Dashboard
    }
    ];
    

    在你的 LandingPage.vue 文件中写入:

    <router-link :to="{name:'dashboard'}">Dashboard</router-link>
    

    【讨论】:

      【解决方案2】:

      你在路线上打错了:

      path: '/dasboard',
      

      另外,路由的name 需要一个字符串,而不是组件。

      【讨论】:

        猜你喜欢
        • 2019-10-28
        • 1970-01-01
        • 2019-08-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-02
        • 2021-06-29
        • 1970-01-01
        相关资源
        最近更新 更多