Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

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