问一个关于Vue路由初始化时传默认参数的问题
<template>
<div class="container">
<div class="content">
<router-view></router-view>
</div>
</div>
</template>
<script>
import VueRouter from 'vue-router';
import PostList from './posts';
export default {
props: ['outside'],
router: new VueRouter({
mode: 'history',
routes: [{
path: '/',
component: PostList,
name: 'post_index',
props: {outside: outside}
}]
})
};
</script>
本身是个组件,请问我要怎么在这里把outside
的参数传给PostList
这个组件
1 回复
<template>
<div class="container">
<div class="content">
<router-view :initialPosts="outside.posts"></router-view>
</div>
</div>
</template>
<script>
import VueRouter from 'vue-router';
import PostList from './posts';
export default {
props: ['outside'],
router: new VueRouter({
mode: 'history',
routes: [{
path: '/',
component: PostList,
name: 'post_index',
props: true
}]
})
};
</script>
解决了,正确做法是这样