2017-07-19 79 views
0

如何在下列表達式中將Vue的變量放入Laravel的小鬍子括號中?Vue內部的刀片 - 語法

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

這引發了我如下錯誤:

Parse error: syntax error, unexpected '}', expecting ',' or ')'

回答

0

問題是你試圖訪問一個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. 

這是接近它的一種方法。