【发布时间】:2020-08-18 10:44:55
【问题描述】:
我的这段代码只有在你点击“/”时才有效,但我希望这些组件在我登陆页面时加载而不必点击它
const Foo = { template: '<div>foo</div>' }
const Bar = { template: '<div>bar</div>' }
const Baz = { template: '<div>baz</div>' }
const router = new VueRouter({
mode: 'history',
routes: [
{ path: '/',
components: {
default: Foo,
a: Bar,
b: Baz
}
},
{
path: '/other',
components: {
default: Baz,
a: Bar,
b: Foo
}
}
]
})
new Vue({
router,
el: '#app'
})
我的路由器文件
<div id="app">
<h1>Named Views</h1>
<ul>
<li>
<router-link to="/">/</router-link>
</li>
<li>
<router-link to="/other">/other</router-link>
</li>
</ul>
<router-view class="view one"></router-view>
<router-view class="view two" name="a"></router-view>
<router-view class="view three" name="b"></router-view>
</div>
我希望加载 Foo 和 Bar 和 Baz 而无需单击它
这是jsfiddle
【问题讨论】:
标签: vue.js vue-router