Vue读取本地md文件

使用 $http 方式获取

1
npm install vue-resource --save-dev

news_list.vue

1
2
3
4
5
6
7
<yd-layout style="margin-top: 10px">
<yd-cell-group title="" class="demo-small-pitch">
<yd-cell-item v-for="title in titles" v-bind:key="title" arrow type="link" v-bind:href="'/news_detail/' + title">
<span slot="left">{{ title }}</span>
</yd-cell-item>
</yd-cell-group>
</yd-layout>

news_detail.vue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<template>
<!--<div class="article" v-html="compiledMarkdown" v-highlight></div>-->
<vue-markdown class="article" v-highlight :source="content"></vue-markdown>
</template>

<script>
import VueMarkdown from 'vue-markdown'
import marked from 'marked'

export default {
name: 'newsDetail',
data () {
return {
content: '',
title: this.$route.params.title
}
},
components: {
'vue-markdown': VueMarkdown // 声明组件
},
created () {
var self = this
this.$http.get('static/content/news/' + this.title + '.md').then((response) => {
console.log(response.body)
self.content = response.body
})
},
computed: {
compiledMarkdown () {
return marked(this.content, { sanitize: true })
}
}
}
</script>

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :