Giter VIP home page Giter VIP logo

Comments (3)

marc7000 avatar marc7000 commented on May 12, 2024 1

Maybe this can help:
#127

CC: @sirockin

from json-editor.

marc7000 avatar marc7000 commented on May 12, 2024

Checkout the example below...

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <h2>JSON-Editor</h2>
    <div id='editorHolder'></div>
    <button id='getValue'>Get value (console.log)</button>
    <button id='setValue'>Set value (console.log)</button>
  </div>
</template>

<script>
import '@json-editor/json-editor'
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  },
  mounted () {
    const el = document.getElementById('editorHolder')
    const JSONEditor = window.JSONEditor
    const editor = new JSONEditor(el, {
      schema: {
        type: 'object',
        title: 'Car',
        properties: {
          make: {
            type: 'string',
            enum: [
              'Toyota',
              'BMW',
              'Honda',
              'Ford',
              'Chevy',
              'VW'
            ]
          },
          model: {
            type: 'string'
          },
          year: {
            type: 'integer',
            enum: [
              1995, 1996, 1997, 1998, 1999,
              2000, 2001, 2002, 2003, 2004,
              2005, 2006, 2007, 2008, 2009,
              2010, 2011, 2012, 2013, 2014
            ],
            default: 2008
          },
          safety: {
            type: 'integer',
            format: 'rating',
            maximum: '5',
            exclusiveMaximum: false,
            readonly: false
          }
        }
      }
    })

    document.getElementById('getValue').addEventListener('click', () => {
      console.log(editor.getValue())
    })

    document.getElementById('setValue').addEventListener('click', () => {
      editor.setValue({make: 'Toyota', model: 'Yaris', year: 2014, safety: 5})
      console.log(editor.getValue())
    })
  }
}
</script>

from json-editor.

amitlevy21 avatar amitlevy21 commented on May 12, 2024

@marc7000 I tried the example which gave me the following error:
webpack-internal:///./node_modules/vue/dist/vue.esm.js:592 [Vue warn]: Error in mounted hook: "TypeError: JSONEditor is not a constructor"
It rendered this:
image
The buttons do not write to console.

Can you please assist?

from json-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.