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. celery+redis 怎么看redis里面的内容2. 为什么redis中incr一个“0” 会报错?3. javascript - 最近用echarts做统计图时遇到两个问题!!4. android - 优酷的安卓及苹果app还在使用flash技术吗?5. css内联样式的style6. python - 使用scrapy框架爬百度图片被墙7. java - 一个泛型标签问题8. java类中的成员成员变量赋值之后什么时候会被回收,有什么办法监听到某一个对象被回收吗9. css - input中transition 设置background-color过渡,chrome浏览器页面初始化渲染会有过度效果10. nginx - 关于vue项目部署到ngnix后出现的问题

网公网安备