代码之家  ›  专栏  ›  技术社区  ›  Mladen Skrbic

将路由器参数传递给组件对象

  •  1
  • Mladen Skrbic  · 技术社区  · 6 年前

    我有视图,我想基于路由器参数加载SVG,我已经安装了Vue加载器,如果我硬编码它,它就会工作。

    <template>
    <div>
      <suit/>
    </div>
    </template>
    
    <script>
    export default {
      components:{
    
        suit: ()=>import('../assets/svg/'+Param+'.svg')
      }
    }
    </script>
    
    <style>
    </style>
    

    这就是我所拥有的。而不是 Param 我想得到 this.route.params 但是当我尝试这个的时候 undefined 这是合乎逻辑的,因为组件包装器是对象。这里有传递变量的方法吗?还是必须重做整个过程?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Daniel Elkington    6 年前

    而不是 this.route.params ,在应该使用的组件中 this.$route.params . Vue Router Docs .