如何在带有Proyect Symfony的vueJS中使用路径树枝-如何正确使用FSRouting

时间:2019-06-12 05:45:30

标签: symfony webpack vuejs2 twig

我有一个Vue代码,但我需要在twig中显示一个链接:

<template>
<div class="col t-blk text-center d-flex justify-content-around">                                                       
<a class="btn btn-primary btn-md border-r-0 d-table py-2 px-4" href="{{path('corpasesoria')}}">Con Asesor</a>
<a class="btn btn-primary btn-md border-r-0 d-table py-2 px-4" id="step01-tab" data-toggle="tab" href="#step01" role="tab" aria-controls="step01" aria-selected="false">Sin Asesor</a>
</div>
</template>

但是在编译webpack时,它在twig的链接中显示错误,无法进行高级操作。

这是错误:

ERROR  Failed to compile with 1 errors                                                                     00:58:12

 error  in ./assets/components/Corporativo/Corporativo.vue?vue&type=template&id=270a4b6a&scoped=true&

Module Error (from ./node_modules/vue-loader/lib/loaders/templateLoader.js):
(Emitted value instead of an instance of Error) 

  Errors compiling template:

  href="{{path('corpasesoria')}}": Interpolation inside attributes has been removed. Use v-bind or the colon shorthand instead. For example, instead of <div id="{{ val }}">, use <div :id="val">.

  15 |                                                                                          <div class="row">
  16 |                                                                                                  <div class="col t-blk text-center d-flex justify-content-around">
  17 |                                                                                                          <a class="btn btn-primary btn-md border-r-0 d-table py-2 px-4" href="{{path('corpasesoria')}}">Con Asesor</a>
     |                                                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  18 |                                                                                                          <a class="btn btn-primary btn-md border-r-0 d-table py-2 px-4" id="step01-tab" data-toggle="tab" href="#step01" role="tab" aria-controls="step01" aria-selected="false">Sin Asesor</a>
  19 |                                                                           

你有什么主意吗?

3 个答案:

答案 0 :(得分:1)

这里是一个示例

import RoutingData from '../../../../dist/js/fos_js_routes';

从“ fos-routing”导入路由;

Routing.setData(RoutingData); 导出默认路由;

答案 1 :(得分:0)

感谢slmder-h的帮助 首先,您需要安装:npmjs.com/package/fos-routing

npm install fos-routing --save

然后,您需要阅读symfony文档:https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/usage.html

在终端之后

# Symfony Flex
bin/console fos:js-routing:dump --format=json --target=public/js/fos_js_routes.json

在.vue或.js文件中

const routes = require ('../../ public / js / fos_js_routes.json');
import Routing from '../../vendor/friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js';

Routing.setRoutingData (routes);
Routing.generate ('asesoriajson');

最后是控制器:

/**
 * @Route("/corporativo/asesoriajson",
 *     options = { "expose" = true },
 *     name = "asesoriajson",
 *       
 * )
 */
 public function asesoriajson(Request $request, SendMail $Sendmail)
 {
    $response = array();
    $response['type'] = null;
    $response['title'] = null;
    $response['message'] = null;

    $response['type'] = 'success';
    $response['title'] = 'Success';
    $response['message'] = 'Usted decidio utilizar un asesor'; 
    return new JsonResponse($response, 200);                    
}

答案 2 :(得分:0)

您可以尝试使用fosjsrouring捆绑包在js内生成链接 https://symfony.com/doc/master/bundles/FOSJsRoutingBundle/index.html