您的位置:首页技术文章
文章详情页

javascript - vue-router怎么不能实现跳转呢

【字号: 日期:2023-02-28 11:16:16浏览:46作者:猪猪

问题描述

根据文档的例子试了一下vue-router用在项目中,一进入首页的路径是test.administer/index,但是根据路由配置,不是应该进入首页后跳转到Login.vue这个组件的内容吗?我根据以下的配置,当前进入首页后,显示的是App.vue里面的内容。。

index.blade.php:

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>1</title> <!--styles--> <link rel='stylesheet' href='https://www.haobala.com/wenda/{{ asset(’css/app.css’) }}'></head><body> <p id='app'></p> <!--scripts--> <script src='https://www.haobala.com/wenda/{{ asset(’js/main.js’) }}'></script></body></html>

main.js:

import Vue from ’vue’import VueRouter from ’vue-router’import VueResource from ’vue-resource’import ElementUI from ’element-ui’import ’element-ui/lib/theme-default/index.css’Vue.use(VueRouter)Vue.use(ElementUI)Vue.use(VueResource)import App from ’./App.vue’import Home from’./components/Home.vue’import Login from’./components/Login.vue’const router = new VueRouter({ routes:[{ path: ’/index’, component: Login, children: [{ path: ’homepage’, component: Home} ]} ]})new Vue(Vue.util.extend({ router },App)).$mount(’#app’)

App.vue:

<template> <p id='app'><h1>hello world</h1><router-view></router-view> </p></template>

login.vue:

<template> <p>loginpage</p></template>

问题解答

回答1:

你哪里有配置是 首页是 Login component 组件嘛

默认需要 /

routes:[{ path: ’/’, component: Login, children: [{ path: ’homepage’, component: Home} ]} ]

如果你配置成 /index

那么对应网址是

test.administer/index/#/index

test.administer/index/#/index/homepage

另外 app.vue 里面的 hello world 会始终显示的

回答2:

没有看到你的login路由在哪里,路由的话<router-view></router-view>间的视图会跳,但外面的内容还是保留的。

回答3:

{ path: ’homepage’, component: Home}应该是{ path: ’/homepage’, component: Home}

标签: JavaScript
相关文章: