javascript - vue-router怎麼不能實現跳轉呢
phpcn_u1582
phpcn_u1582 2017-07-05 10:58:58
0
3
852

根據文件的範例試了一下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="{{ asset('css/app.css') }}">
</head>
<body>
    <p id="app"></p>
    <!--scripts-->
    <script src="{{ 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>
phpcn_u1582
phpcn_u1582

全部回覆(3)
迷茫

你哪裡有設定是 首頁是 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 會永遠顯示的


过去多啦不再A梦

沒有看到你的login路由在哪裡,路由的話間的視圖會跳,但外面的內容還是保留的。

習慣沉默

雷雷

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板