npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

json-editor-vue3

v1.1.1

Published

[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url]

Downloads

3,235

Readme

json-editor-vue3

NPM version npm download

基于 jsoneditor 开发的vue3 json editor,支持全屏编辑,有完善的事件回调,可以在失去焦点时,对编辑器内容做校验。

安装

npm install json-editor-vue3

使用

全局引入

import Vue from 'vue'
import JsonEditorVue from 'json-editor-vue3'

Vue.use(JsonEditorVue)

组件引入

import JsonEditorVue from 'json-editor-vue3'

export default {
  name: 'app',
  components: {
    JsonEditorVue
  },
  data() {
    return {
      data: {
        "hello": "vue"
      }
    }
  },
  methods: {}
}

模板使用

<json-editor-vue class="editor" v-model="data" />

参数

| Name | Type | Description | Default | | ---- | ---- | ----------- | ------- | | modelValue | Object | 要编辑的json值 |--| | options | Object | jsoneditor 的options,参考configuration-options |--| | currentMode | String | 当前编辑模式 | code | | modeList | Array | 可选的编辑模式列表 | ["tree", "code", "form", "text", "view"] | | language | Array | 语言 | en |

事件

| Name | Type | Description | | ----- | ---------|-------------- | | update:modelValue|(json: Object) => void | json 更新 | | change |(json: Object) => void; | json 更新 | | textSelectionChange|(editor:Editor, start: number, end: number, text: string) => void; | 选择文本时触发的回调函数 | | selectionChange| (editor:Editor, start: number, end: number) => void; | 选择节点时触发的回调函数 | | focus |(editor:Editor, target: HTMLElement) => void; | 获取焦点 | | blur |(editor:Editor, target: HTMLElement) => void; | 时区焦点 | | colorPicker| (editor:Editor, parent: any, color: string, onChange: any) => void; | 当用户点击颜色时触发回调函数 | | validationError| (editor:Editor, errors: ValidationError[]) => void; | 如果发现任何类型的错误,则会使用错误数据调用此回调 |

常见问题

vue3+ts无法渲染,报错jsoneditor does not provide an export named 'default'

这是因为vite对commonjs兼容性太差,导致无法引入jsoneditor,可以使用@originjs/vite-plugin-commonjs插件解决。

// vite.config.js
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
export default defineConfig({
  plugins: [vue(),viteCommonjs()],
})

Vite的 官方文档 也有提到:Pre-bundle them to improve page loading speed and convert CommonJS / UMD modules to ESM.所以不需要这个plugin,不过得直接在项目源代码里 import 'jsoneditor' 才会转换。

参考 issue #4

公众号

欢迎关注作者公众号前端方程式,如果您有任何问题,也可以通过该公众号联系作者。

捐赠 json-editor-vue3 的开发

json-editor-vue3 的文档和代码完全开源,如果该项目有帮助到你的开发工作,你可以捐赠json-editor-vue3的研发工作,捐赠无门槛,哪怕是一杯可乐也好。