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

vue3 使用 jsoneditor

vue3 使用 jsoneditor

在main.js中引入 样式文件

import 'jsoneditor/dist/jsoneditor.css'

复制代码放到文件中就能用了
jsoneditor.vue

<template><div ref="jsonDom" style="width: 100%; height: 460px"></div>
</template>
<script setup lang="ts">
import { ref, onMounted, watchEffect } from 'vue'
import JsonEditor from 'jsoneditor'
interface validateResult {path: Array<string | number>message: string
}
const props = defineProps<{option: anyvalidate?: (val: any) => validateResult
}>()
const emit = defineEmits(['update:modelValue', 'change', 'customValidation'])const jsonDom = ref(null)
const validate = (res: any, editor: any) => {try {emit('change', {success: res.length === 0 && typeof editor.get() !== 'number',json: editor.getText()})} catch (error) {console.log(error)}
}
onMounted(() => {const options = {history: false,sortObjectKeys: false,mode: 'code',modes: ['code', 'text'],onChange() {editor.validate().then((res: any) => validate(res, editor))},onBlur() {try {editor.set(eval(`(${editor.getText()})`))editor.validate().then((res: any) => validate(res, editor))} catch (error) {console.log(error)}},onValidate: props.validate,onValidationError: function (errors: any) {errors.forEach((error: any) => {switch (error.type) {case 'validation': // schema validation errorbreakcase 'customValidation': // custom validation erroremit('customValidation')breakcase 'error': // json parse erroremit('change', {success: false,json: editor.getText()})break}})}}const editor = new JsonEditor(jsonDom.value, options)watchEffect(() => {editor.set(props.option)editor.validate().then((res: any) => validate(res, editor))})
})
</script>
http://www.lryc.cn/news/279778.html

相关文章:

  • 若依前后端分离版使用mybatis-plus实践教程
  • SpringBoot-Dubbo-Zookeeper
  • 华为HCIE课堂笔记第十二章 ICMPv6和NDP协议
  • GNSS科研常用相关网站及资源
  • 进程的创建与回收学习笔记
  • 【CCNet】《CCNet:Criss-Cross Attention for Semantic Segmentation》
  • Qt QSQlite数据库插入字符串中存在单个双引号或单个单引号解决方案
  • Linux系统中的IP地址、主机名、和域名解析
  • soc算法【周末总结】
  • SpringBoot之优化高并发场景下的HttpClient并提升QPS
  • go-zero 如何在任意地方获取yaml中的值
  • C++20结构化绑定应用实例(二百五十六)
  • 改进YOLOv8注意力系列四:结合中心化特征金字塔EVCBlock、大核卷积注意力LKA_Attention、全局注意力MobileViTAttention
  • idea中使用Lombok 失效,@Slf4j 找不到符号的解决办法
  • MySQL修炼手册8:约束与完整性:保证数据的一致性
  • React入门 - 03(初识 React 组件和 JSX)
  • 华为OD机试 - 反射计数(Java JS Python C)
  • Linux系统中使用systemctl命令控制软件的启动和关闭
  • 2024年01月微软更新Bug 已解决 !Explorer.EXE 提示:Windows无法访问指定设备、路径或文件。你可能没有适当的权限访问该项目。
  • Qt/QML编程学习之心得:slider(34)
  • 使用metricbeat 监控多ES集群
  • 阿里云服务器+宝塔 (尝试部署一个最简单的静态页面)
  • 每日一题——LeetCode1160.拼写单词
  • 物联网协议Coap之Core和NetWork简介
  • Java SE入门及基础(10)
  • Docker五部曲之二:Docker引擎
  • 简单说一下原型与原型链
  • 11Spring IoC注解式开发(上)(元注解/声明Bean的注解/注解的使用/负责实例化Bean的注解)
  • k8s 部署Jenkins项目
  • #每日一题#力扣#2085.统计出现过一次的公共字符串