简体   繁体   English

vue 中的 JsonEditor 组件未显示

[英]JsonEditor component in vue is not showing

I am having trouble showing my JsonEditor component.我无法显示我的 JsonEditor 组件。 This is the code that i am working with:这是我正在使用的代码:

<template>
  <v-app>
  <div class="admin">

    <v-alert v-if="info.showAlert"
      value=true
      :type="info.alertType">
    {{info.message}}
    </v-alert>

    <h2>Welcome to scope360 admins area. A place to edit scope360 configurations</h2>
    <v-btn class="test" @click="switchEditClicked">{{switchButtonMessage}}</v-btn>
    <div class= "editorComponents">
      <div v-if="showJsonEditor" class="editor">
        <json-editor is-edit="true" v-model="editedConfig" ></json-editor>
        <v-btn @click="previewClicked">Preview Changes</v-btn>
      </div>
      <div v-if="!showJsonEditor" class="jsonDiff">
        <vue-json-compare :oldData="originalConfig" :newData="editedConfig"></vue-json-compare>
        <v-btn @click="saveClicked">Save</v-btn>
        <v-btn @click="cancelPreviewClicked">Cancel</v-btn>
      </div>
    </div>
  </div>
</v-app>
</template>

<script>

import JsonEditor from 'vue-edit-json'
import vueJsonCompare from 'vue-json-compare'

import{getConfig,updateConfig} from "../utils/network";


export default{

  components: {
   'vue-json-compare' : vueJsonCompare,
   'json-editor' : JsonEditor
 },

  data: function () {
    return {
      originalConfig: {},
      editedConfig: {},
      showJsonEditor: true,
      switchButtonMessage: "plain text",
      info : {
        showAlert: false,
        alertType: "success",
        message: ""
      },
   }
  },

What am i missing?我错过了什么? There is no errors when running.运行时没有错误。 I am retrieving information from my backend to display some JSON information.我正在从后端检索信息以显示一些 JSON 信息。

*The component has worked before, after som changes in design it stopped working *Yes, i have checked if the data i am retrieving to display is correct and exists *该组件以前工作过,在设计发生某些更改后它停止工作 *是的,我检查了我要检索显示的数据是否正确且存在

Update更新

I made it work again but i would still love to know why my first attempt is not working?我让它再次工作,但我仍然想知道为什么我的第一次尝试不起作用?

This works:这有效:

import Vue from 'vue'
Vue.use(JsonEditor)

  components: {
   'vue-json-compare' : vueJsonCompare

 },

//HTML
  <JsonEditor is-edit="true" v-model="editedConfig" ></JsonEditor>

Update 2, Link to JsonEditor更新 2,链接到 JsonEditor

https://www.npmjs.com/package/vue-edit-json https://www.npmjs.com/package/vue-edit-json

To answer your question on why it's not importing the component with your first approach.回答您关于为什么不使用您的第一种方法导入组件的问题。 That's because the author decided to make it a plugin instead of importable component.那是因为作者决定将其作为插件而不是可导入组件。 (See Vue docs on plugin ). (请参阅插件上的 Vue 文档)。

Such that when you do import on this component, it may be imported but never rendered since it's written without exporting the default module.这样,当您对此组件进行import时,它可能会被导入但永远不会呈现,因为它是在没有导出default模块的情况下编写的。

If you need to register this component by the import keyword, you could specify the complete path to the component file itself.如果您需要通过import关键字注册该组件,您可以指定组件文件本身的完整路径。

import JsonEditor from "vue-edit-json/src/JsonEditor";

new Vue({

  components: {
    JsonEditor
  }
    
}

And that should give you the same effect.这应该会给你同样的效果。


BTW, a quick tip for you:顺便说一句,给你一个快速提示

When defining a component with PascalCase, you can use either case when referencing its custom element.使用 PascalCase 定义组件时,您可以在引用其自定义元素时使用任何一种情况。 That means both <my-component-name> and <MyComponentName> are acceptable.这意味着<my-component-name><MyComponentName>都是可以接受的。

So in your case, since you seem to want to have the components in kebab-case, you could drop the component "alias" name from the components object.因此,在您的情况下,由于您似乎希望将组件放在 kebab-case 中,您可以从components对象中删除组件“别名”名称。

import VueJsonCompare from 'vue-json-compare';

components: {
  VueJsonCompare
}

// ...

<vue-json-compare :oldData="originalConfig" :newData="editedConfig"></vue-json-compare>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM