我有简单的模态窗口 plan.vue 带插槽
...
<div class="plan__content">
<slot></slot>
</div>
...
还有 example.vue 使用它
<button
@click="showPlan"
>
Show plan
</button>
<plan
v-if="isPlanVisible"
@closePlan="closePlan"
>
</plan>
我还有 Twig 文件 plan.html.twig
{% block field %}
<table id="plan_table">
<caption>
<h2> {{smth.name}} </h2>
</caption>
...
</table>
{% endblock %}
我可以在这里添加我的 Twig <plan> </plan>
不知何故?我试图找到解决方案,但只找到了如何将 vue 添加到 twig,而不是相反
最佳答案
您无法将 twig 文件嵌入 Vue 组件并渲染它。您有两种选择:
- 您在“Vue 代码”中实现了 twig 模板,并且根本不使用 twig 模板。
- 您可以通过来自后端端点的 HTTP 请求加载渲染的 Twig 模板,并在 Vue 组件内通过 v-html 属性渲染响应。
关于php - 如何在vue中使用twig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69819241/