Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set initial content #3

Open
marekkaczkowski opened this issue Mar 15, 2017 · 4 comments
Open

Set initial content #3

marekkaczkowski opened this issue Mar 15, 2017 · 4 comments

Comments

@marekkaczkowski
Copy link

Hey,
I'm trying to fill Brace with data that I receved from response <brace>{{ jsonData }}</brace> jsonData is defined in data container but then nothing happens. Works ok for regular textarea.
Do I have to use Ace mechanism like editor.setValue(jsonData)?

Thanks 😁

@igorbabko
Copy link

You can try to use v-html="jsonData"

@marekkaczkowski
Copy link
Author

marekkaczkowski commented Mar 28, 2017

v-html breaks Brace instance 😢

<template>
    <div class="block is-flex">
        <brace style="height: 300px" v-html="jsonDetails" :mode="'json'">
        </brace>
    </div>
</template>

<script>
import Vue from 'vue'
import Brace from 'vue-bulma-brace'

export default {
  components: {
    Brace
  },

  data () {
    return {
      jsonDetails: ''
    }
  },

  methods: {
    openJson (event) {
      var url = 'url to my api'
      var self = this

      this.$http.get(url).then(response => {
        self.jsonDetails = JSON.stringify(response.body, null, 2)
      }, response => {
        console.log(String(response.body))
      })
    }
  }
}
</script>

@fundon can you tell us if it is possible at the moment? Looks like it lacks of method setValue like:

    setValue (value) {
      editor.setValue(value)
    }

Thanks

@rankam
Copy link

rankam commented Mar 28, 2017

@marekkaczkowski I was having the same issue and this worked for me.

<template>
    <brace style="height: 500px; margin-left: 20px"
      :fontsize="'22px'"
      :theme="'monokai'"
      :mode="'javascript'"
      :codefolding="'markbegin'"
      :softwrap="'free'"
      :selectionstyle="'text'"
      :highlightline="true">
    </brace>
</template>

<script>
import Brace from 'vue-bulma-brace';
import * as brace from 'brace';
var editor 

export default {
  components: {
    Brace
  },
  data() {
    return {
      events: []
    }
  },
  mounted() {
    this.$http.get('/event_schema').then(response => {
        this.events = response.data
        this.editor = brace.edit('vue-bulma-editor')
        this.editor.session.setValue(JSON.stringify(this.events))
    })
  }
}
</script>

@marekkaczkowski
Copy link
Author

Yes! Thanks @rankam, works like a charm ✨
I had to modify source a bit cuz there is a hardcoded id 'vue-bulma-editor' here is pull req #5 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants