duankan8739 2015-11-07 15:37
浏览 89
已采纳

如何将Vue.js变量导入php函数?

I have a Laravel 5.1 project that I'm trying to improve and now migrating some features to Vue.js to make it more interactive and stuff.

In my view I have

<img src="{{ file_storage_path($product->path) }}" alt="{{$product->name}}"/>

This is default implementation using Laravel's blade.

Now, when I delegate this to the Vue.js I would have something like this

<img src="{{ file_storage_path(product.path) }}" alt="@{{product.name}}"/>

But this of course fails. So I need both - to invoke a php-function and at the same time to render Vue data.

I tried this

src="{{ file_storage_path( @{{product.path}} ) }}"

But of course this fails too. any suggestions?

  • 写回答

1条回答 默认 最新

  • dqsxsmi3704 2015-11-07 18:01
    关注

    Since I couldn't find a way to inline both blade syntax and Vue.js variable rendering I see the solution is to first invoke the php function and then append the Vue.js rendering to it.

    So, the workaround would be

     <img :src="'{{ file_storage_path('/') }}' + image.path" alt="@{{product.name}}" />
    

    This solution would work only for specific case, it doesn't get answer to my original question, when a php function actually needs to accept a Vue variable. But in this case, I can simply append values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器