dqvj51875 2017-11-24 14:48
浏览 101
已采纳

如何将js变量传递给laravel中的url标记

I do have a variable in vuejs :

invoice.id 

I want to add this id to a laravel route in blade like so :

<a href="/invoice/{{invoice.id}}/history" />

but it does not work, is there any way how to pass that variable to the route ?

I am getting invoices as an array like so :

<script>
    import {statusColor} from "../util";

    export default {
        props: ['invoice', 'index'],
</script>

invoice its an array.

  • 写回答

2条回答 默认 最新

  • dragon19720808 2017-11-24 15:12
    关注

    Bind href in vuejs as :href or v-bind:href

    <a :href="'/invoice/'+invoice.id+'/history'" />
    

    Check below example

    var V = new Vue({
      el:"#app",
      data:{
        invoice:{id:111}
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.8/vue.js"></script>
    <div id="app">
    <a :title="'/invoice/'+invoice.id+'/history'" :href="'/invoice/'+invoice.id+'/history'">Hover me to check href value</a>
    </div>

    Here is the example with child component value assinged by props

    var Child = {
      template:`<div>Child component : <a :title="'/invoice/'+invoice.id+'/history'" :href="'/invoice/'+invoice.id+'/history'">Hover me to check href value</a></div>`,
      props:['invoice'],
    }
    var V = new Vue({
      el:"#app",
      data:{
        invoice:{id:111}
      },
      components:{
        Child
      }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.8/vue.js"></script>
    <div id="app">
    
    <child :invoice="invoice"></child>
    </div>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥15 基于图神经网络的COVID-19药物筛选研究