【问题标题】:vue.js routing shows the same component after first navigationvue.js 路由在第一次导航后显示相同的组件
【发布时间】:2017-10-03 16:07:10
【问题描述】:

我的main.js如下

import Vue from 'vue'
import App from './App'
import vueResource from 'vue-resource'
import VueRouter from 'vue-router'

import Registration from './components/Registration.vue'
import Login from './components/Login.vue'



Vue.config.productionTip = false
Vue.use(vueResource)
Vue.use(VueRouter)


const router = new VueRouter({
    mode: 'history',
    base: __dirname,
    routes: [
        { path: '/', component: Registration },
        { path: '/login', component: Login },
        { path: '*', redirect: '/' }
    ]
})

new Vue({
  el: '#app',
  router: router,
  template: '<router-view></router-view>'
})

app.vue

<template>
  <div id="app">
      <router-link to="/">Registration</router-link>
      <router-link to="/login">Login</router-link>
      <router-view></router-view>
  </div>
</template>

它会加载带有注册链接和登录链接的 app.vue。注册组件默认加载。当我单击登录链接时,将显示登录组件。当我再次点击注册时,网址发生了变化,但没有显示注册组件。

【问题讨论】:

  • 根据你的 app.vue 的内容你可以把它作为一个组件加载,然后 new Vue({ el: '#app', router, template: '', components : { 应用 } })
  • 你的问题不是用代码发表评论
  • @Deepak :您的解决方案对我有用。谢谢。
  • 将其作为答案发布。

标签: vue.js


【解决方案1】:

根据你的 app.vue 的内容,你可以将它作为一个组件加载,然后

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

【讨论】:

    猜你喜欢
    • 2018-02-21
    • 2022-10-14
    • 2017-07-25
    • 1970-01-01
    • 2019-04-10
    • 2018-03-05
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    相关资源
    最近更新 更多