【问题标题】:Vue inside of blade - syntax刀片内部的 Vue - 语法
【发布时间】:2017-12-25 06:39:04
【问题描述】:

如何将Vue 的变量放入下面表达式中Laravel 的小胡子括号中?

<a href="{{URL::route('frontend.article.show', ['slug' => '@{{article.slug}}', 'categoryId' =>'@{{ @article.id}}'])}}">"@{{article.title}}"></a>

这会引发如下错误:

解析错误:语法错误,意外 '}',期待 ',' 或 ')'

【问题讨论】:

    标签: javascript laravel-5 laravel-blade


    【解决方案1】:

    问题是您试图在 PHP 语句(服务器端)中访问 Vue 变量(客户端)。解决此问题的一种方法是在 Vue 的 mounted() 方法中创建链接。您可以按以下方式执行此操作:

    首先创建如下标签

    <a id="@{{ article.id }}" href="">@{{ article.title }}</a> 
    

    然后,您需要在 Vue 的 mounted() 方法(或 created())中创建适当的链接

    let path = "{{ route('frontend.article.show', ['slug' => 1, 'categoryId' => 2]) }}";
    let url = path.replace(1, article.slug).replace(2, article.id);
    
    // manipulate the DOM from here or pass it through to your data.
    

    这是处理它的一种方法。

    【讨论】:

      猜你喜欢
      • 2017-09-12
      • 1970-01-01
      • 2020-08-19
      • 2016-12-29
      • 2017-08-30
      • 2018-11-04
      • 2019-08-02
      • 2017-08-18
      • 2021-11-27
      相关资源
      最近更新 更多