Passing props to Vue.js components instantiated by Vue-router

前端 未结 6 1084
日久生厌
日久生厌 2020-11-29 04:15

Suppose I have a Vue.js component like this:

var Bar = Vue.extend({
    props: [\'my-props\'],
    template: \'

This is bar!

\' });
<
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 04:45

    In the router,

    const router = new VueRouter({
      routes: [
        { path: 'YOUR__PATH', component: Bar, props: { authorName: 'Robert' } }
      ]
    })
    

    And inside the component,

    var Bar = Vue.extend({
        props: ['authorName'],
        template: '

    Hey, {{ authorName }}

    ' });

提交回复
热议问题