如何将laravel route参数传递给vue

Roc*_*cky 2 php laravel vue.js laravel-5.3 vuejs2

我刚接触vue&我做了很多谷歌,但没有找到任何与我目前的情况相匹配的解决方案所以不知道我怎么能在vue组件中传递路线,有没有办法将这个laravel路由传递到vue模板中下面.我的vue是位置资源/ assets/js这里是代码

               <template>
                   <a href={{route('/')}}></a>//i want to pass laravel route 
                                               //to view component this line 
                                                //throw error
               </template>
Run Code Online (Sandbox Code Playgroud)

route(web.php)代码

        Route::get('/' , function(){

                 Return view('homepage');
          });
Run Code Online (Sandbox Code Playgroud)

我想将此url传递给位置(vue)为的vue组件 resource/assets/js

tia*_*ias 9

您必须将其作为vue组件中的prop传递.它们是两个不同的步骤.

  1. Laravel吐出已编译的模板

  2. Vue解析组件并初始化它们.

在步骤2,您必须使用在步骤1解析的路径传递道具

像这样的东西

<my-component route="{{ route('my-route') }}"></my-component>
Run Code Online (Sandbox Code Playgroud)

然后在你的组件内

<template>
    <a :href="route">CLICK HERE</a>
</template>

<script>
...
props: {
    route: { type: String, required: true }
}
...
</script>
Run Code Online (Sandbox Code Playgroud)