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/>