javascript - vue-router怎么不能实现跳转呢
问题描述
根据文档的例子试了一下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}
相关文章:
1. docker-compose中volumes的问题2. boot2docker无法启动3. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””4. docker安装后出现Cannot connect to the Docker daemon.5. nignx - docker内nginx 80端口被占用6. 关于docker下的nginx压力测试7. node.js - antdesign怎么集合react-redux对input控件进行初始化赋值8. dockerfile - 为什么docker容器启动不了?9. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?10. java - SSH框架中写分页时service层中不能注入分页类

网公网安备