当前位置: 首页 > news >正文

vnodeToString函数把vnode转为string(innerhtml)

函数

function vnodeToString(vnode) {// 如果是文本节点,直接返回文本内容if (['string', 'boolean', 'undefined', 'null', 'number'].includes(typeof vnode)) {return vnode;}// 转换节点的属性为字符串形式const attrs = Object.keys(vnode.attrs || {}).map((key) => `${key}="${vnode.attrs[key]}"`).join(' ');// 转换子节点为字符串形式const children = (vnode.children || []).map(vnodeToString).join('');// 返回包含标签名、属性和子节点的字符串形式return `<${vnode.tag} ${attrs}>${children}</${vnode.tag}>`;
}

因为业务中需要低代码配置表格,配置文件就用的vnode格式

vue中封装渲染

<template><div v-html="str"></div>
</template><script>
function vnodeToString(vnode) {// 如果是文本节点,直接返回文本内容if (['string', 'boolean', 'undefined', 'null', 'number'].includes(typeof vnode)) {return vnode;}// 转换节点的属性为字符串形式const attrs = Object.keys(vnode.attrs || {}).map((key) => `${key}="${vnode.attrs[key]}"`).join(' ');// 转换子节点为字符串形式const children = (vnode.children || []).map(vnodeToString).join('');// 返回包含标签名、属性和子节点的字符串形式return `<${vnode.tag} ${attrs}>${children}</${vnode.tag}>`;
}
export default {name: "originalTableConfig",props: {config: {type: Object,default: () =>({})}},data(){return {str:'',}},watch: {config:{handler(){this.setStr()},immediate: true,}},methods: {setStr(){this.str = vnodeToString(this.config)},getHtmlStr(){// html前缀 + 样式const htmlPre = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"></meta><title>Title</title></head><body>`// html后缀const htmlSuf = `</body></html>`// 拼接const res = htmlPre + this.str + htmlSuf// 返回return res},}
}
</script>

使用案例

<template><div><original-table-config :config="myConfig"/></div>
</template><script>
import OriginalTableConfig from "@/views/originalTableConfig/components/originalTableConfig.vue";
// {
//   tag: '',// 元素标签
//   attrs: {}, // 标签属性
//   children: [],// 子元素
// }
export default {components: {OriginalTableConfig},data() {return {myConfig: {}}},mounted() {this.setTable()},methods: {setTable(){const commonTrStyle = "padding: 4px; margin-bottom: 10px;"const commonAttrsLabel = {style: 'text-align: right;' + commonTrStyle}const commonAttrsValue = {style: 'border-bottom: 1px solid black;' + commonTrStyle}this.myConfig = {tag: 'table',children: [{tag: 'tbody',attrs: {style: "width: 685px;"},children: [{tag: 'tr',children: [{tag: "th", attrs: {style: "width: 120px;"}},{tag: "th", attrs: {style: "width: 120px"}},{tag: "th", attrs: {style: "width: 100px"}},{tag: "th", attrs: {style: "width: 120px"}},{tag: "th", attrs: {style: "width: 100px"}},{tag: "th", attrs: {style: "width: 120px"}},]},{tag: 'tr',children: [{tag: 'td',attrs: {style: "font-size: 18px; text-align: center;",colspan: '6'},children: ['撒打发士大夫啥打发大水发收到']},{tag: 'td'},{tag: 'td'},{tag: 'td'},{tag: 'td'},{tag: 'td'}]},{tag: 'tr',children: [{tag: 'td',attrs: {style: "font-size: 18px; text-align: center;padding-bottom: 10px",colspan: '6'},children: ['xxxxxxxxxxx发送到发大水发斯蒂芬表']},{tag: 'td'},{tag: 'td'},{tag: 'td'},{tag: 'td'},{tag: 'td'}]},{tag: 'tr',children: [{tag: 'td', children: ['xxx金额:'], attrs: commonAttrsLabel},{tag: 'td', children: ['xxxxxxxxx', '元'], attrs: commonAttrsValue},{tag: 'td', children: ['xxx金额:'], attrs: commonAttrsLabel},{tag: 'td', children: ['xxxxxxxxx', '元'], attrs: commonAttrsValue},{tag: 'td', children: ['xxx金额:'], attrs: commonAttrsLabel},{tag: 'td', children: ['xxxxxxxxx', '元'], attrs: commonAttrsValue}]},{tag: 'tr',children: [{tag: 'td', children: ['xxx金额:'], attrs: commonAttrsLabel},{tag: 'td', children: ['xxxxxxxxx', '元'], attrs: commonAttrsValue},{tag: 'td', children: ['xxx金额:'], attrs: commonAttrsLabel},{tag: 'td', children: ['xxxxxxxxx', '元'], attrs: commonAttrsValue},{tag: 'td', children: ['xxx金额:'], attrs: commonAttrsLabel},{tag: 'td', children: ['xxxxxxxxx', '元'], attrs: commonAttrsValue}]},{tag: 'tr',children: [{tag: 'td', children: ['xxx金额:'], attrs: commonAttrsLabel},{tag: 'td', children: ['xxxxxxxxx', '元'], attrs: commonAttrsValue},{tag: 'td', children: ['xxx金额:'], attrs: commonAttrsLabel},{tag: 'td', children: ['xxxxxxxxx', '元'], attrs: commonAttrsValue},{tag: 'td', children: ['xxx金额:'], attrs: commonAttrsLabel},{tag: 'td', children: ['xxxxxxxxx', '元'], attrs: commonAttrsValue}]},{tag: 'tr',children: [{tag: 'td', children: ['xxx负责人:'], attrs: commonAttrsLabel},{tag: 'td', children: [''], attrs: commonAttrsValue},{tag: 'td', children: ['xxx领导:'], attrs: commonAttrsLabel},{tag: 'td', children: [''], attrs: commonAttrsValue},{tag: 'td', children: ['xxx人:'], attrs: commonAttrsLabel},{tag: 'td', children: [''], attrs: commonAttrsValue}]},{tag: 'tr',children: [{tag: 'td', children: ['xxx部门:'], attrs: commonAttrsLabel},{tag: 'td', children: [''], attrs: commonAttrsValue},{tag: 'td'},{tag: 'td'},{tag: 'td', children: ['xxx单位:'], attrs: commonAttrsLabel},{tag: 'td', children: [''], attrs: commonAttrsValue}]},{tag: 'tr',children: [{tag: 'td', children: ['xxx日期:'], attrs: commonAttrsLabel},{tag: 'td', children: [''], attrs: commonAttrsValue},{tag: 'td', children: ['xxx日期:'], attrs: commonAttrsLabel},{tag: 'td', children: [''], attrs: commonAttrsValue},{tag: 'td', children: ['xxx日期:'], attrs: commonAttrsLabel},{tag: 'td', children: [''], attrs: commonAttrsValue}]},]}]}}}
}
</script>

相关文章:

vnodeToString函数把vnode转为string(innerhtml)

函数 function vnodeToString(vnode) {// 如果是文本节点&#xff0c;直接返回文本内容if ([string, boolean, undefined, null, number].includes(typeof vnode)) {return vnode;}// 转换节点的属性为字符串形式const attrs Object.keys(vnode.attrs || {}).map((key) > …...

【Halcon】C# HTuple多参数设置小技巧

比如&#xff0c;在halcon中我们经常这么写&#xff1a; dev_disp_text (hello, window, 100, 200, red, [box,shadow],[true,false])[‘box’,‘shadow’] 和 [‘true’,‘false’] 成对出现。 可以同时对多个参数设置。 如果用halcon翻译C#&#xff0c;你会得到&#xff1a…...

此芯科技加入绿色计算产业联盟,参编绿色计算产业发展白皮书

近日&#xff0c;此芯科技正式加入绿色计算产业联盟&#xff08;Green Computing Consortium&#xff0c;简称GCC&#xff09;&#xff0c;以Arm架构通用智能CPU芯片及高能效的Arm PC计算解决方案加速构建软硬协同的绿色计算生态体系&#xff0c;推动绿色计算产业加速发展。 继…...

webrtc 生成unpack_aecdump工具

1.download webrtc-code https://git.ringcentral.com/build/webrtc-build 2.下载webrtc代码 3.terminal 进入src目录下 4.构建目录&#xff1a; terminal执行&#xff1a;gn gen out/Release --argsis_component_buildfalse 5.构建可执行文件&#xff1a; terminal执行…...

数据结构第四课 -----线性表之队列

作者前言 &#x1f382; ✨✨✨✨✨✨&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f367;&#x1f382; ​&#x1f382; 作者介绍&#xff1a; &#x1f382;&#x1f382; &#x1f382; &#x1f389;&#x1f389;&#x1f389…...

蓝桥杯 第 3 场算法双周赛4,7题

迷宫逃脱 一眼数字三角形模型&#xff0c;因为是要求最大值&#xff0c;而且对转移状态有限制&#xff0c;所以需要注意dp状态的初始化&#xff0c;可以将所有状态赋值为-0x7f&#xff0c;然后将dp[0][1]和dp[1][0]初始化为0&#xff0c;又因为考虑到起始点a[1][1]&#xff0c…...

西安有哪些比较好的设计院?西安名企设计院介绍!

1、西北综合勘察设计研究院&#xff08;地址&#xff1a;陕西省西安市习武园9号&#xff09; 西北综合勘察设计研究院始建于1952年&#xff0c;是西北地区建设领域成立最早、规模最大的的综合性甲级勘察设计咨询科研单位&#xff0c;公司业务以工程勘察、建筑设计、市政设计、…...

Java获取Jar、War包路径,并生成可编辑修改的本地配置文件

前言 本地的可修改配置文件的编写理应是一个很常用的功能&#xff0c;但由于数据库的存在&#xff0c;它鲜少被提及&#xff0c;大多数我们直接存储到数据库中了。 以至于现今&#xff0c;除了没接触数据库的新手时常使用它以外&#xff0c;它没有太多的出场机会。 也因此&am…...

FPGA UDP RGMII 千兆以太网(4)ARP ICMP UDP

1 以太网帧 1.1 1以太网帧格式 下图为以太网的帧格式: 前导码(Preamble):8 字节,连续 7 个 8’h55 加 1 个 8’hd5,表示一个帧的开始,用于双方 设备数据的同步。 目的 MAC 地址:6 字节,存放目的设备的物理地址,即 MAC 地址 源 MAC 地址:6 字节,存放发送端设备的…...

【视觉SLAM十四讲学习笔记】第二讲——初识SLAM

专栏系列文章如下&#xff1a; 【视觉SLAM十四讲学习笔记】第一讲 一个机器人&#xff0c;如果想要探索某一块区域&#xff0c;它至少需要知道两件事&#xff1a; 我在什么地方——定位周围环境是什么样——建图 一方面需要明白自身的状态&#xff08;即位置&#xff09;&#…...

Python交易-通过Financial Modeling Prep (FMP)选择行业

介绍 在您的交易旅程中,无论您是在寻找理想的股票、板块还是指标,做出明智的决策对于您的成功至关重要。然而,收集和分析所需的大量数据可能相当艰巨。财务建模准备 (FMP) API的...

AI创作系统ChatGPT网站源码+详细搭建部署教程+支持DALL-E3文生图/支持最新GPT-4-Turbo-With-Vision-128K多模态模型

一、AI创作系统 SparkAi创作系统是基于OpenAI很火的ChatGPT进行开发的Ai智能问答系统和Midjourney绘画系统&#xff0c;支持OpenAI-GPT全模型国内AI全模型。本期针对源码系统整体测试下来非常完美&#xff0c;可以说SparkAi是目前国内一款的ChatGPT对接OpenAI软件系统。那么如…...

快速生成力扣链表题的链表,实现快速调试

关于力扣链表题需要本地调试创建链表的情况 我们在练习链表题&#xff0c;力扣官方需要会员&#xff0c;我们又不想开会员&#xff0c;想在本地调试给你们提供的代码 声明&#xff1a;本人也是参考的别人的代码&#xff0c;给你们提供不同语言生成链表 参考链接&#xff1a; 参…...

threejs(13)-着色器设置点材质

着色器材质内置变量 three.js着色器的内置变量&#xff0c;分别是 gl_PointSize&#xff1a;在点渲染模式中&#xff0c;控制方形点区域渲染像素大小&#xff08;注意这里是像素大小&#xff0c;而不是three.js单位&#xff0c;因此在移动相机是&#xff0c;所看到该点在屏幕…...

计算机网络专栏 学习导航or使用说明

计算机网络各章笔记 计算机网络_第一章_计算机网络的概述 计算机网络_第二章_物理层 计算机网络_第三章_数据链路层 计算机网络_第四章网络层_网络层概述_网际协议IP 计算机网络各章习题 计算机网络第一章习题_网络概述 计算机网络第二章习题_物理层 计算机网络第三章习…...

git clone:SSL: no alternative certificate subject name matches target host name

git clone 时的常见错误&#xff1a; fatal: unable to access ‘https://ip_or_domain/xx/xx.git/’: SSL: no alternative certificate subject name matches target host name ‘ip_or_domain’ 解决办法&#xff1a; disable ssl verify git config --global http.sslVe…...

代码随想录图论|130. 被围绕的区域 417太平洋大西洋水流问题

130. 被围绕的区域 **题目&#xff1a;**给你一个 m x n 的矩阵 board &#xff0c;由若干字符 ‘X’ 和 ‘O’ &#xff0c;找到所有被 ‘X’ 围绕的区域&#xff0c;并将这些区域里所有的 ‘O’ 用 ‘X’ 填充。 题目链接&#xff1a;130. 被围绕的区域 解题思路&#xff1a…...

Outlook无法显示阅读窗格

Outlook无法显示阅读窗格 故障现象 Outlook主界面不显示阅读窗格 故障截图 故障原因 阅读窗格被关闭 解决方案 1、打开Outlook - 视图 – 阅读窗格 2、选择“靠右”或者“底部”&#xff0c;正常显示阅读窗格...

tensorflow 1.15 gpu docker环境搭建;Nvidia Docker容器基于TensorFlow1.15测试GPU;——全流程应用指南

前言: TensorFlow简介 TensorFlow 在新款 NVIDIA Pascal GPU 上的运行速度可提升高达 50%&#xff0c;并且能够顺利跨 GPU 进行扩展。 如今&#xff0c;训练模型的时间可以从几天缩短到几小时 TensorFlow 使用优化的 C 和 NVIDIA CUDA 工具包编写&#xff0c;使模型能够在训练…...

一个22届被裁前端思想上得转变

距离上篇文章已经过去了三个多月&#xff0c;这个三个月&#xff0c;经历了技术攻坚&#xff0c;然后裁员&#xff0c;退房&#xff0c;回老家&#xff0c;找工作。短短的几个月&#xff0c;就经历社会的一次次毒打&#xff0c;特别是找工作&#xff0c;虽然算上实习我也有两年…...

国防科技大学计算机基础课程笔记02信息编码

1.机内码和国标码 国标码就是我们非常熟悉的这个GB2312,但是因为都是16进制&#xff0c;因此这个了16进制的数据既可以翻译成为这个机器码&#xff0c;也可以翻译成为这个国标码&#xff0c;所以这个时候很容易会出现这个歧义的情况&#xff1b; 因此&#xff0c;我们的这个国…...

VB.net复制Ntag213卡写入UID

本示例使用的发卡器&#xff1a;https://item.taobao.com/item.htm?ftt&id615391857885 一、读取旧Ntag卡的UID和数据 Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click轻松读卡技术支持:网站:Dim i, j As IntegerDim cardidhex, …...

《Qt C++ 与 OpenCV:解锁视频播放程序设计的奥秘》

引言:探索视频播放程序设计之旅 在当今数字化时代,多媒体应用已渗透到我们生活的方方面面,从日常的视频娱乐到专业的视频监控、视频会议系统,视频播放程序作为多媒体应用的核心组成部分,扮演着至关重要的角色。无论是在个人电脑、移动设备还是智能电视等平台上,用户都期望…...

centos 7 部署awstats 网站访问检测

一、基础环境准备&#xff08;两种安装方式都要做&#xff09; bash # 安装必要依赖 yum install -y httpd perl mod_perl perl-Time-HiRes perl-DateTime systemctl enable httpd # 设置 Apache 开机自启 systemctl start httpd # 启动 Apache二、安装 AWStats&#xff0…...

【CSS position 属性】static、relative、fixed、absolute 、sticky详细介绍,多层嵌套定位示例

文章目录 ★ position 的五种类型及基本用法 ★ 一、position 属性概述 二、position 的五种类型详解(初学者版) 1. static(默认值) 2. relative(相对定位) 3. absolute(绝对定位) 4. fixed(固定定位) 5. sticky(粘性定位) 三、定位元素的层级关系(z-i…...

Linux-07 ubuntu 的 chrome 启动不了

文章目录 问题原因解决步骤一、卸载旧版chrome二、重新安装chorme三、启动不了&#xff0c;报错如下四、启动不了&#xff0c;解决如下 总结 问题原因 在应用中可以看到chrome&#xff0c;但是打不开(说明&#xff1a;原来的ubuntu系统出问题了&#xff0c;这个是备用的硬盘&a…...

Ascend NPU上适配Step-Audio模型

1 概述 1.1 简述 Step-Audio 是业界首个集语音理解与生成控制一体化的产品级开源实时语音对话系统&#xff0c;支持多语言对话&#xff08;如 中文&#xff0c;英文&#xff0c;日语&#xff09;&#xff0c;语音情感&#xff08;如 开心&#xff0c;悲伤&#xff09;&#x…...

智能仓储的未来:自动化、AI与数据分析如何重塑物流中心

当仓库学会“思考”&#xff0c;物流的终极形态正在诞生 想象这样的场景&#xff1a; 凌晨3点&#xff0c;某物流中心灯火通明却空无一人。AGV机器人集群根据实时订单动态规划路径&#xff1b;AI视觉系统在0.1秒内扫描包裹信息&#xff1b;数字孪生平台正模拟次日峰值流量压力…...

鸿蒙DevEco Studio HarmonyOS 5跑酷小游戏实现指南

1. 项目概述 本跑酷小游戏基于鸿蒙HarmonyOS 5开发&#xff0c;使用DevEco Studio作为开发工具&#xff0c;采用Java语言实现&#xff0c;包含角色控制、障碍物生成和分数计算系统。 2. 项目结构 /src/main/java/com/example/runner/├── MainAbilitySlice.java // 主界…...

Springboot社区养老保险系统小程序

一、前言 随着我国经济迅速发展&#xff0c;人们对手机的需求越来越大&#xff0c;各种手机软件也都在被广泛应用&#xff0c;但是对于手机进行数据信息管理&#xff0c;对于手机的各种软件也是备受用户的喜爱&#xff0c;社区养老保险系统小程序被用户普遍使用&#xff0c;为方…...