matt-oconnell / vue-monaco-editor

Monaco Editor Vue Component
MIT License
254 stars 59 forks source link

how to change the code #11

Open flyinhigh opened 6 years ago

flyinhigh commented 6 years ago

the :code is the initial code to show . it works only when it renders at the first time. if I want to change the code , how can I do ?

zantiu commented 6 years ago

Use setValue() on the editor object returned by the onMounted method: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.icodeeditor.html#setvalue

The example shows how to get the editor object:

module.exports = {
  components: {
    Monaco
  },
  data() {
    return {
      code: '// Type away! \n',
      options: {
        selectOnLineNumbers: false
      }
    };
  },
  methods: {
    onMounted(editor) {
      this.editor = editor;
    },
    onCodeChange(editor) {
      console.log(editor.getValue());
    }
  }
};