Vue读取本地md文件

使用 $http 方式获取

npm install vue-resource --save-dev

news_list.vue

<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

<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>
上一篇 Markdown CSS样式
下一篇 Vue中使用highlight.js
目录
文章列表
1 多次重定向中http-referer的变化
多次重定向中http-referer的变化
2
Tinker + Bugly + Jenkins 爬坑之路
Tinker + Bugly + Jenkins 爬坑之路
3
Python搭建HTTP服务器:PyCharm配置virtualenv使用Flask
Python搭建HTTP服务器:PyCharm配置virtualenv使用Flask
4
安装Kubernetes高可用
安装Kubernetes高可用
5
Homestead注意问题
Homestead注意问题
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。