【问题标题】:How to pass route parameter in a href using Alpine.js如何使用 Alpine.js 在 href 中传递路由参数
【发布时间】:2022-01-23 05:20:21
【问题描述】:

我第一次在 Laravel 项目中使用 Alpine.js,想在组件中添加一个 href 标签,但是我不确定如何正确路由参数

<template x-for="(post, index) in posts" :key="index">
    <a x-bind:href="post.id">
        <p class="mt-2 block text-sm font-medium text-gray-900 truncate pointer-events-none">
            <span x-text="post.text"></span>
        </p>
    </a>
</template>

重定向到

/id 

并传递 id 但我需要转到指定的路线帖子并期待

/posts/id

如果我添加

 <a x-bind:href="posts/post.id">

结果是重定向

/posts/NaN

【问题讨论】:

    标签: laravel alpine.js


    【解决方案1】:

    你可以试试这个:&lt;a x-bind:href="posts + '/' + post.id"&gt;

    【讨论】:

    猜你喜欢
    • 2018-05-21
    • 2021-08-13
    • 2023-01-04
    • 2020-07-15
    • 2021-09-09
    • 2019-09-06
    • 2021-04-04
    • 1970-01-01
    • 2020-10-20
    相关资源
    最近更新 更多