簡體   English   中英

為什么 vue-router 不顯示組件?

[英]Why vue-router doesn't show component?

免責聲明! 此代碼供私人使用,因此它可以包含輪子

我在沒有 webpack 等的情況下完成這項任務。

我正在嘗試制作組件加載器。 好吧, getComponents() 工作正常並以字符串形式返回 html 代碼。 當我打開 /userlists 時,路由器什么也不顯示。 所以, route / 不應該工作,但它工作! 我哪里出錯了?

裝載機:

const getComponent = name => {
    return document.getElementsByClassName('component '+name)[0].outerHTML
}

const mainComponent = {
    template: '<h3>Hand mailer<p>)</p></h3>'
}

const userLists = {
    template: getComponent('userslist')
}

成分:

<div class="component userlists">
        <p>
            Hello vue!
        </p>
    </div>

路由器:

const router = new VueRouter({
    hashbang: true,
    routes: [
        {
            path: '/',
            component: mainComponent
        },
        {
            path: '/userlists',
            component: userLists
        }
    ]
})

這是我的錯,我添加了屬性display: none; 到類組件)))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM