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='http://m.cgvv.com.cn/wenda/{{ asset(’css/app.css’) }}'></head><body> <p id='app'></p> <!--scripts--> <script src='http://m.cgvv.com.cn/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. python中return 語句與 分支語句連用問題2. thinkphp3 count()方法必須加上字段?3. node.js - webpack-dev-server正常運行,webpack打包卻出錯,怎么辦?4. 我何時應該在Java中使用JFrame.add(component)和JFrame.getContentPane()。add(component)5. 這是什么情況???6. javascript - 項目的公共文件如圖片JS等文件放在 云上,webroot只放jsp文件,怎么將靜態文件通過配置文件引入,sp求大神指導7. android - 哪位大神知道java后臺的api接口的對象傳到前端后輸入日期報錯,是什么情況?求大神指點8. 怎么php怎么通過數組顯示sql查詢結果呢,查詢結果有多條,如圖。我要forsearch里面echo9. nginx 504 Gateway Time-out 請問如何設置10. update方法不能更新字段值為0的數據
