在 vue 组件属性中访问 laravel 路由

accessing laravel routes in vue component attribute

我正在尝试访问我的 Reply.vue 文件中的命名 laravel 路由。我想做的是将此路由作为属性传递给我的 reply 组件。但是在编译时出现以下错误:

invalid expression: Unexpected token : in

http://tddforum.com/thread/reply/10

Raw expression: :route="http://tddforum.com/thread/reply/10"

如您所见,路由值已正确分配给 :route 属性,但由于上述错误,页面无法加载。这是我的回复组件的第一行:

<reply :attributes="{{ $reply}}" :route="{{ route('reply.update',$reply->id) }}" inline-template>

这里有什么问题?

谢谢, 耶斯

您使用的 v-bind 将值计算为 JavaScript,但您实际上传递的是字符串文字,因此只需删除 v-bind(冒号):

<reply :attributes="{{ $reply}}" route="{{ route('reply.update',$reply->id) }}" inline-template>

如果 reply 也是一个字符串,那么你也需要做同样的事情。