推荐一款好用的Web端JSON在线编辑器svelte-jsoneditor

JSON编辑器

今天推荐一款Web前端好用的JSON编辑器,适用于 Chrome, Firefox, Safari, Opera, Edge, Internet Explorer 11主流浏览器,并且可以使用Javascript、Vue、React开发。

支持功能:

  • JSON编辑
  • JSON格式化
  • 树形结构
  • 收起展开
  • 搜索
  • 上一步和下一步
  • 对齐文本
  • 复制粘贴
  • 显示行号

JSON Editor简介

JSON Editor仓库地址,拥有9.7k+的 star。

在线JSON解析工具就是使用了JSON Editor的功能。

官方介绍:

JSON Editor is a web-based tool to view, edit, format, and validate JSON. It has various modes such as a tree editor, a code editor, and a plain text editor.

The editor can be used as a component in your own web application. The library can be loaded as CommonJS module, AMD module, or as a regular javascript file.

Supported browsers: Chrome, Firefox, Safari, Opera, Edge, Internet Explorer 11.

svelte-jsoneditor简介

svelte-jsoneditor是JSON Editor项目的继承者,可以直接使用。

svelte-jsoneditor仓库地址

官方介绍:

A web-based tool to view, edit, format, transform, and validate JSON

The library is written with Svelte, but can be used in any framework (React, Vue, Angular, plain JavaScript)

集成使用

先看一下效果图:

code模式:

树形模式:

安装依赖

npm install svelte-jsoneditor

代码示例

下面是Vue代码实现,其他框架可以查看官网文档。

<template>
  <div class="login">
    <div style="width: 40%; height: 50%; margin: 0 auto" ref="editor"></div>
  </div>
</template>

<script>
// 引入组件
import {JSONEditor} from "svelte-jsoneditor";
export default {
mounted() {
	let manifest = `{
	  "platformId": "",
	  "supports": [
	    "android",
	    "ios"
	  ],
	  "statusbar": {
	    "immersed": true,
	    "style": "light"
	  }
	}`
	// 将json字符串转成对象
    manifest = JSON.parse(manifest);
    // 设置content
    let content = {
      text: undefined,
      json: manifest
    }
    // 创建对象
    this.editor = new JSONEditor({
      target: this.$refs["editor"],
      props: { // 设置属性
        content: content,
        mode: "code",
        mainMenuBar: true,
        navigationBar: true,
        indentation: 4,
        tabSize: 4,
        escapeControlCharacters: false,
        onChange: (updatedContent, previousContent, patchResult) => {
          console.log('onChange', updatedContent, previousContent, patchResult)
          content = updatedContent
        }
      }
    });
  },
  beforeUnmount() {
  	// 销毁对象,释放内存
    this.editor.destroy();
    this.editor = null;
  }
}
</script>

<style lang="less" scoped>
/*去除右侧外链文字*/
/deep/ .jse-powered-by.svelte-1yyupsl {
  display: none;
}
</style>
参数属性

svelte-jsoneditor提供了很多的属性和方法可以对编辑器进行配置:

在这里插入图片描述
这里只截图一部分,其他部分还需要去官网查看。

使用技巧

如果想要对编辑器样式进行定制,需要F12进入调试模式,然后找到相应的样式进行改造。
例如:需要去掉工具栏右侧的外链。

在Vue代码的样式中需要重写它的class:

<style lang="less" scoped>
/*去除右侧外链文字*/
/deep/ .jse-powered-by.svelte-1yyupsl {
  display: none;
}
</style>

今天的分享就到这里,希望能够帮助大家,JSON Editor的其他功能还需要大家去研究探索。

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Svelte-routing 是一个基于 Svelte 的轻量级路由库,它提供了基本的路由功能,包括路由参数、嵌套路由、重定向等特性。使用 Svelte-routing 非常简单,你可以按照以下步骤进行配置: 1. 安装 Svelte-routing 你可以使用 npm 或 yarn 安装 Svelte-routing: ``` npm install --save svelte-routing ``` 或 ``` yarn add svelte-routing ``` 2. 导入 Router 和 Route 组件 在 Svelte 应用中,你需要使用 Router 和 Route 组件来定义路由规则。你可以在需要使用路由的组件中导入这两个组件: ```js import { Router, Route } from 'svelte-routing'; ``` 3. 定义路由规则 使用 Router 和 Route 组件,你可以定义应用的路由规则。例如,你可以在 App.svelte 文件中定义两个路由规则,分别对应着应用的 / 和 /about 路径: ```html <Router> <Route path="/" component={Home} /> <Route path="/about" component={About} /> </Router> ``` 在这个例子中,Home 和 About 分别是两个 Svelte 组件,它们会在对应的路由被匹配时被渲染。 4. 使用路由参数 Svelte-routing 支持路由参数,你可以在路由规则中使用冒号(:)来定义动态参数。例如,你可以定义一个 /user/:id 路径,其中 :id 表示一个动态参数。当用户访问 /user/123 时,Svelte-routing 会自动将参数传递给对应的组件。你可以在组件中使用 $routeParams.id 来获取该参数。例如: ```html <!-- 定义路由规则 --> <Route path="/user/:id" component={User} /> <!-- User 组件中获取参数 --> <script> export let $routeParams; console.log($routeParams.id); </script> ``` 5. 使用重定向 Svelte-routing 还支持重定向功能,你可以在路由规则中使用 redirect 属性来实现重定向。例如,你可以将 /about 路径重定向到 /about-us 路径: ```html <Route path="/about" redirect="/about-us" /> ``` 以上就是使用 Svelte-routing 实现基本路由功能的步骤。Svelte-routing 还支持嵌套路由、路由守卫等高级功能,你可以查阅官方文档来学习更多内容。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ruiurrui

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值