2016-09-25 81 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>