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

Close immediately after opening #45

Open
GoodwinGuo opened this issue Dec 29, 2023 · 0 comments
Open

Close immediately after opening #45

GoodwinGuo opened this issue Dec 29, 2023 · 0 comments

Comments

@GoodwinGuo
Copy link

Thanks

Hi. Many thanks to StackEdit and stackedit.js! They are all great works!

Problem

I trying to use it in my Vue2 project according to the documentation below.
stackedit.js

It always closes immediately after opening.

like this.

StackEdit js

Code

stackedit.js version: "stackedit-js": "^1.0.7",.

Vue code

<template>
  <div>
    <div>
      <button type="primary" @click="newMarkdown">New MarkDown</button>
    </div>
    <div>
      <textarea>Hello **Markdown** writer!</textarea>
    </div>
  </div>
</template>

<script>
import Stackedit from 'stackedit-js';

export default {
  components: {
  },
  data() {
    return {
      
    };
  },
  methods: {
    newMarkdown() {
      const el = document.querySelector('textarea');
      const stackedit = new Stackedit();

      // Open the iframe
      stackedit.openFile({
        name: 'Filename', // with an optional filename
        content: {
          text: el.value // and the Markdown content.
        }
      });

      // Listen to StackEdit events and apply the changes to the textarea.
      stackedit.on('fileChange', (file) => {
        el.value = file.content.text;
      });
    },
  },
  mounted() {

  },
};
</script>
<style lang="scss" scoped>
</style>

Problem code

I suspect the cause of the problem is here.

    // Add message handler
    this.$messageHandler = (event) => {
      console.log(event);
      if (event.origin === this.$origin && event.source === iframeEl.contentWindow) {
        switch (event.data.type) {
          ...
          default:
            this.close();
        }
      }
    };

There's a message there that triggers close.

message

Suggested solutions

src\index.js

    // Add message handler
    this.$messageHandler = (event) => {
      if (event.origin === this.$origin && event.source === iframeEl.contentWindow && event.data && event.data.type) {
        ...
      }
    };
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

1 participant