javascript - vue-router怎么不能實(shí)現(xiàn)跳轉(zhuǎn)呢
問題描述
根據(jù)文檔的例子試了一下vue-router用在項(xiàng)目中,一進(jìn)入首頁的路徑是test.administer/index,但是根據(jù)路由配置,不是應(yīng)該進(jìn)入首頁后跳轉(zhuǎn)到Login.vue這個組件的內(nèi)容嗎?我根據(jù)以下的配置,當(dāng)前進(jìn)入首頁后,顯示的是App.vue里面的內(nèi)容。。
index.blade.php:
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>1</title> <!--styles--> <link rel='stylesheet' href='http://www.piao2010.com/wenda/{{ asset(’css/app.css’) }}'></head><body> <p id='app'></p> <!--scripts--> <script src='http://www.piao2010.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 組件嘛
默認(rèn)需要 /
routes:[{ path: ’/’, component: Login, children: [{ path: ’homepage’, component: Home} ]} ]
如果你配置成 /index
那么對應(yīng)網(wǎng)址是
test.administer/index/#/index
test.administer/index/#/index/homepage
另外 app.vue 里面的 hello world 會始終顯示的
回答2:沒有看到你的login路由在哪里,路由的話<router-view></router-view>間的視圖會跳,但外面的內(nèi)容還是保留的。
回答3:{ path: ’homepage’, component: Home}應(yīng)該是{ path: ’/homepage’, component: Home}
相關(guān)文章:
1. javascript - 這兩種函數(shù)寫法各有什么好處?2. 微信支付 - python做微信企業(yè)付款出現(xiàn)CA證書錯誤3. 前端 - css3傾斜帶來問題部分?4. node.js - vue 子組件的菜單 如何與 父組件 通信?5. javascript - node環(huán)境使用vue-cli 配置代理6. 了解Java中的有限泛型。有什么意義?7. angular.js - 在ionic下,利用javascript導(dǎo)入百度地圖,pc端可以顯示,移動端無法顯示8. html5 - HTML代碼中的文字亂碼是怎么回事?9. html5 - 如何禁止百度轉(zhuǎn)碼?10. angular.js - vue or angular.2 or react
