[英]Dynamically add wrapper element in vue3 composition api
Consider a component below, which accepts tag
as props.考虑下面的一个组件,它接受
tag
作为道具。
<template>
<input v-model="model"/>
</template>
<script>
export default {
name: "InputComponent",
props: {
tag: {
type: String,
required: false,
default: null,
}
}
}
</script>
I want passing the props div
as tag
value should return dom below.我想将道具
div
作为tag
值传递,应该在下面返回 dom。
<div>
<input v-model="model"/>
</div>
Solution with composition api is advantange.
具有成分 api 的溶液是有利的。
<template>
<component :is="tag">
<input v-model="model"/>
</component>
</template>
<script>
export default {
name: "InputComponent",
props: {
tag: {
type: String,
required: false,
default: null,
}
}
}
</script>
should work.应该管用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.