Blade 内部的 Vue - 语法
Vue inside of blade - syntax
如何将 Vue
的变量放入以下表达式的 Laravel
的小胡子括号中?
<a href="{{URL::route('frontend.article.show', ['slug' => '@{{article.slug}}', 'categoryId' =>'@{{ @article.id}}'])}}">"@{{article.title}}"></a>
这会抛出如下错误:
Parse error: syntax error, unexpected '}', expecting ',' or ')'
问题是您试图在 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.
这是处理它的一种方法。
如何将 Vue
的变量放入以下表达式的 Laravel
的小胡子括号中?
<a href="{{URL::route('frontend.article.show', ['slug' => '@{{article.slug}}', 'categoryId' =>'@{{ @article.id}}'])}}">"@{{article.title}}"></a>
这会抛出如下错误:
Parse error: syntax error, unexpected '}', expecting ',' or ')'
问题是您试图在 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.
这是处理它的一种方法。