问一个关于Vue路由初始化时传默认参数的问题
发布于 6 年前 作者 jiyarong 3563 次浏览 来自 问答
<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>

解决了,正确做法是这样

回到顶部