您现在的位置是:首页 >技术教程 >vue3+ts 引入 json-editor-vue3 网站首页技术教程

vue3+ts 引入 json-editor-vue3

理想和远方_在路上 2025-02-19 00:01:03
简介vue3+ts 引入 json-editor-vue3

cnpm install json-editor-vue3 jsoneditor

//模板使用

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

// 组件内引用

import JsonEditorVue from 'json-editor-vue3'

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

 引用完之后有报错

报错内容  SyntaxError: The requested module '/node_modules/jsoneditor/dist/jsoneditor.min.js?v=00499bcc' does not provide an export named 'default' (at json-editor.vue:2:8)

解决方案: 

1.// 组件内引用

import 'jsoneditor'
import JsonEditorVue from 'json-editor-vue3'

2.根目录创建 declaration.d.ts 文件

文件内容如下:

declare module 'json-editor-vue3'

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。