【问题标题】:Vue JS text interpolation expression returning html or componentVue JS文本插值表达式返回html或组件
【发布时间】:2017-10-25 02:50:29
【问题描述】:

如何使用文本插值在模板内渲染组件?我尝试了以下代码:

<template>
   <div> {{ booleanValue ? "<my-component />" : "Some Text" }} </div>
</template>

但这是打印带有“双胡须”的实际代码,删除组件标签并渲染组件。

{{ booleanValue ? "" : "Some Text" }}

【问题讨论】:

    标签: javascript html vue.js vuejs2 vue-component


    【解决方案1】:

    我仍然不知道如何使用文本插值来做到这一点,但我找到了一种更简单的方法:Conditional Rendering

     <div v-if="booleanValue"> 
        <my-component /> 
     </div>
     <div v-else>Some Text</div>
    

    【讨论】:

    • 这是正确的做法。文本插值是 - 等待它 - 仅文本。没有组件。
    猜你喜欢
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 2020-07-27
    相关资源
    最近更新 更多