javascript - VueJS - 如何在 HTML 字符串中转换 this.$slots.default?
问题描述
我使用 Vue CLI 创建了一个项目,现在我需要挂载函数中的插槽值。
我可以使用this.$slots.default访问插槽,并且我得到了 VNode 数组。
现在我需要将 VNode 数组转换为 HTML 字符串,例如:
const html = `<p><strong>Lorem</strong> ipsum</p>`;
我目前的代码如下所示:
<TestComponent field="website" :data="document">
<p><strong>Lorem</strong> ipsum</p>
</TestComponent>
<template>
<div class="test">
<p>lorem ipsum</p>
</div>
</template>
<script>
export default {
props: ["field", "data"],
data() {
return {
editor: null,
};
},
mounted() {
if (this.$slots.default) {
const html;
console.log(this.$slots.default);
}
},
};
</script>
解决方案
推荐阅读
- swiftui - SwiftUI:呈现具有从帧到帧的自定义过渡的模态视图?
- react-native - 当应用程序在后台时,如何保持 redux saga 响应?
- sql-server - SQL Challenge 将行连接到每个组的末尾
- containers - 使用 aa-genprof 为容器应用程序自动生成配置文件
- node.js - 在某些请求中更改测试库 IP?
- sql - 使用小数(10,1)计算时间时的结果差异
- julia - 从二进制文件中读取数组:“读取文件结尾”错误
- javascript - 移动设备上的 Google Oauth 需要 client_secret 但生成的客户端不提供
- rholang - Rholang 与 AND 和 RevAddress 匹配
- r - LMEST 解码问题