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這個(gè)組件的內(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.aoyou183.cn/wenda/{{ asset(’css/app.css’) }}'></head><body> <p id='app'></p> <!--scripts--> <script src='http://www.aoyou183.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 組件嘛
默認(rèn)需要 /
routes:[{ path: ’/’, component: Login, children: [{ path: ’homepage’, component: Home} ]} ]
如果你配置成 /index
那么對(duì)應(yīng)網(wǎng)址是
test.administer/index/#/index
test.administer/index/#/index/homepage
另外 app.vue 里面的 hello world 會(huì)始終顯示的
回答2:沒有看到你的login路由在哪里,路由的話<router-view></router-view>間的視圖會(huì)跳,但外面的內(nèi)容還是保留的。
回答3:{ path: ’homepage’, component: Home}應(yīng)該是{ path: ’/homepage’, component: Home}
相關(guān)文章:
1. django - 后臺(tái)返回的json數(shù)據(jù)經(jīng)過Base64加密,獲取時(shí)用python如何解密~!2. css3 - 請(qǐng)問一下在移動(dòng)端CSS布局布局中通常需要用到哪些元素,屬性?3. 我在centos容器里安裝docker,也就是在容器里安裝容器,報(bào)錯(cuò)了?4. 我的html頁面一提交,網(wǎng)頁便顯示出了我的php代碼,求問是什么原因?5. tp6表單令牌6. angular.js - 如何通俗易懂的解釋“依賴注入”?7. docker 17.03 怎么配置 registry mirror ?8. node.js - node 客戶端socket一直報(bào)錯(cuò)Error: read ECONNRESET,用php的socket沒問題哈。。9. 老哥們求助啊10. 在MySQL中新增字段時(shí),報(bào)錯(cuò)??
