【发布时间】: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 的语法,但这是基本思想。)