2016-09-25 30 views
0

我正在使用vue-router。將值綁定到鏈接url

如何將值綁定到鏈接?

<a v-link="'people/edit/{{ item.id }}'">Edit</a> 

錯誤:

link="'people/edit/{{ item.id}}'": attribute interpolation is not allowed in Vue.js directives and special attributes. 
+1

'v-link =''people/edit /'+ item.id「'? – Dogbert

+0

@Dogbert它的工作原理... – Alvin

回答

1

您可以簡單地使用+這裏在連接字符串,因爲v-link接受JavaScript表達式:

<a v-link="'people/edit/' + item.id">Edit</a> 

v-link is the directive for enabling user navigation in a router-enabled app. It accepts a JavaScript expression which will be passed to router.go() internally.

https://github.com/vuejs/vue-router/blob/1.0/docs/en/link.md

2

虛連接屬性指定文檔中訪問過的鏈接的顏色,它不是用來作爲你使用它。在vlink的地方使用鏈接href。如下面

<a href="people/edit/${item.id}"></a> 
+0

因爲我們vue-router,鏈接不是http:// localhost:8080 /#!/ people/edit/3871287183 – Alvin

3

不能使用小鬍子到V-鏈接,v鏈接基本上是香草js,並且鬍鬚作爲模板部分是不允許的。

如果您使用的是ES2015,則可以使用模板字符串。

<a v-link="`/people/edit/${item.id}`">Link</a>