Laravel路由到Vue.js路由 [英] Laravel routes to Vue.js routes

查看:80
本文介绍了Laravel路由到Vue.js路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的web.php路由文件中大约有100条路由,现在我开始通过laravel而不是Blade来使用vue.js,所以我也应该在vue路由中写入所有的web.php路由吗?最好的方法是什么?

I have about 100 routes in my web.php route file, and right now i started using vue.js with laravel instead of blade, so should i write all my web.php routes in vue routes also ? what is the best way ?

这是我的web.php laravel路线:

this is my web.php laravel route:

Route::post('/dashboard/widget', 'AdminDashboardController@widget')->name('dashboard.widget');

    Route::get('clients/export/{status?}/{client?}', ['uses' => 'ManageClientsController@export'])->name('clients.export');
    Route::get('clients/create/{clientID?}', ['uses' => 'ManageClientsController@create'])->name('clients.create');
    Route::post('clients', ['uses' => 'ManageClientsController@store'])->name('clients.store');
    Route::resource('clients', 'ManageClientsController', ['expect' => ['create']]);
    ..... and much more ......

我如何在vue.js中表示这条laravel路线,因为我的web.php中有100多个路线

how i can represent this laravel routes in vue.js, since i have more than 100 route in my web.php

谢谢

推荐答案

为此提供了一个库: https://github.com/tighten/ziggy

但是,只有在将Vue组件加载到刀片模板中的情况下,它才有效,而如果您拥有使用Laravel API的完全独立的Vue客户端,则该方法无效.假设是第一种情况,只需安装该库,然后将 @routes 刀片指令添加到您的主刀片文件中:

But it only works if your Vue components are loaded inside blade templates, not if you have a completely separate Vue client that uses a Laravel API. Assuming the first case, just install the library and add the @routes blade directive to your main blade file:

composer require tightenco/ziggy

resources/views/layouts/app.blade.php :

<head>
  <!-- ... -->

  <!-- CSRF Token -->
  <meta name="csrf-token" content="{{ csrf_token() }}">

  <title>{{ config('app.name', 'Laravel') }}</title>

  <!-- Routes -->
  @routes
  <!-- Scripts -->
  <script src="{{ asset('js/app.js') }}" defer></script>

  <!-- ... -->
<head>

然后,您的Javascript和Vue文件中将提供 route 函数,其功能类似于Laravel提供的功能.

And then you'll have the route function available in your Javascript and Vue files, which works like the one provided by Laravel.

这篇关于Laravel路由到Vue.js路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆