【问题标题】:Getting data from PHP controller into Vue从 PHP 控制器获取数据到 Vue
【发布时间】:2019-07-07 17:39:07
【问题描述】:

我有一个用 PHP 编写的后端,带有 Twig 模板和 Vue 组件的前端。我正在尝试将数据从我的 PHP 控制器传递到我的 Vue 组件中,但我真的不知道该怎么做。

假设我的控制器中有这个:

    return $this->render('setting/setting.html.twig', [
  'title' => 'Your Etsy Settings',
  'tab' => 'Settings',
  'sub_title' => 'integrated with etsy',
  'message' => '',
  'settingForm' => $form->createView(),
  'storeId' => $store->getId()
]);

如何在我的 Vue 组件中访问“标题”?我的模板的一部分是 Twig,然后我在 Twig 模板中渲染我的 Vue 组件。

【问题讨论】:

  • 您必须将它们传递给 Twig 模板中的 Vue 组件(作为道具)。类似于<your-vue-component :title="{{ title }}"> 的东西。 (抱歉,我不确切知道 Twig 的语法,但这是基本思想。)

标签: php symfony vue.js twig


【解决方案1】:

可能问题是{{}}然后你可以交换

new Vue({
    delimiters: ['${', '}']
})

...

<your-vue-component :title="${ {{ title }} }">

https://vuejs.org/v2/api/#delimiters

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    相关资源
    最近更新 更多