miaolz123 / vue-markdown

A Powerful and Highspeed Markdown Parser for Vue
https://miaolz123.github.io/vue-markdown/
MIT License
1.89k stars 257 forks source link

How to use external .md file? #52

Closed thearabbit closed 6 years ago

thearabbit commented 6 years ago

I base on Meteor + Vue.

// changelog.md
# Vue markdown
...........
----------
<template>
   <vue-markdown source="./changelog.md"></vue-markdown>
</template>

But don't work, please help me

goldenram commented 6 years ago

Yes, I expected source="filename" to work, but it appears the string is just a text string. I am guessing we have to use axios or some other file loader to do a file load into a string, then pass that into the source attribute.

goldenram commented 6 years ago

Here is quick component I came up with wrap this one:

<template>
    <vue-markdown :source="mdText"></vue-markdown>
</template>

<script>
import axios from 'axios'

export default
{
    name: 'md-viewer',
    props: ["src"],
    data: function()
    {
        return ({"mdText": ""});
    },
    mounted()
    {
        axios.get(this.src).then(response => {this.mdText = response.data})
    }
}
</script>

<style lang="scss"></style>

Then import and call it:

<md-viewer src="file.md"></md-viewer>

thearabbit commented 6 years ago

Thanks for your reply. But don't understand

<md-viewer src="file.md"></md-viewer>
thearabbit commented 6 years ago

Now it works fine.