php 如何将动态数据传递给laravel惯性中的链接

monwx1rj  于 10个月前  发布在  PHP
关注(0)|答案(1)|浏览(64)

我想得到像一个查看更多页面到我的项目,我想从我的后端传递动态数据到链接路由器,以便能够获得一个查看更多页面的确切记录。例如。

<Link :href="route('viewproduct')" class="btn" style="background: #24882c; color: white;">View more</Link>

{{ product.id }}

字符串
我希望能够传递数据到链接,使它看起来像这样:第一个月
我试过像使用data属性一样向它传递数据,但它仍然不起作用

guicsvcw

guicsvcw1#

可以使用管线参数将动态数据传递到链接。假设您已定义了路由,

Route::get('/viewproduct/{productId}', 'ProductController@show')->name('viewproduct');

字符串
在Vue组件中,你可以使用route helper生成包含动态数据(productId)的URL,并将其传递给Link组件:

<template>
  <Link :href="getProductViewLink(product.id)" class="btn" style="background: #24882c; color: white;">View more</Link>
</template>

<script>
export default {
  props: {
    product: Object // Assuming you are passing the product object as a prop to this component
  },
  methods: {
    getProductViewLink(productId) {
      return this.route('viewproduct', { productId });
    }
  }
}
</script>

相关问题