Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 在vue js中传递HTML标记_Vue.js - Fatal编程技术网

Vue.js 在vue js中传递HTML标记

Vue.js 在vue js中传递HTML标记,vue.js,Vue.js,我有一个组件,里面有一个标签,但有时希望它是一个标签,如何传递道具 <template> <p>Hello world</p> </template> 你好,世界 将其作为道具传递,然后使用渲染: <template> <component :is="tag">Hello world</component > </template> <script> expo

我有一个组件,里面有一个
标签,但有时希望它是一个
标签,如何传递道具

<template>
 <p>Hello world</p>
</template>

你好,世界

将其作为道具传递,然后使用渲染:

<template>
 <component :is="tag">Hello world</component >
</template>

<script>
export default{
  name:'MyComponent',
  props:['tag']
}
</script

然后像
hello world

一样使用它会建议为该组件使用插槽,类似这样

<template>
  <slot name="content"></slot>
</template>

当您使用组件时,您可以这样做

<Component>
  <template #content>
    Your content here, whatever you like
  <template/>
<Component/>

你的内容在这里,随你喜欢

您好,谢谢您的回答!这不是我想要的,我有时想显示一个p标记而不是一个具有相同文本内容的h1标记,我想我们需要做一个if-else条件你可以做
嗨,谢谢你的回答,我想你的回答是指一个不显示html标记的道具@fancy56否我的答案是一种在不造成混乱的情况下更改组件内容的正确方法
<Component>
  <template #content>
    Your content here, whatever you like
  <template/>
<Component/>