0

I am trying to import function marked from https://cdn.jsdelivr.net/npm/marked/marked.min.js. I have injected <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> by mount(). But it always throws an error [Vue warn]: Error in render: "ReferenceError: marked is not defined". Why it is not defined even after the script has been added?

<script>
export default {
  name: 'Upload',
  data () {
    return {
      title: '',
      content: ''
    }
  },
  mounted () {
    let externalScript = document.createElement('script')
    externalScript.setAttribute('src', 'https://cdn.jsdelivr.net/npm/marked/marked.min.js')
    Plugin.async = true
    document.head.appendChild(externalScript)
  },
  computed: {
    markdown2html: function () {
      return marked(this.content)
    }
  }
}
</script>
1
  • when app mounted, means all views are rendered. Insert it at head or import it at main.js Commented Jan 25, 2021 at 2:28

1 Answer 1

3

Okay I'm not familiar with Vue, I use React, but normally I would be able to add the script link in the index.html under public folder. Then when everything's built it will be there.

Best option I think would be to install it via npm - npm i marked, then import marked from 'marked' - why not do it this way?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.