{"id":1052,"date":"2023-03-12T10:08:44","date_gmt":"2023-03-12T02:08:44","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1052"},"modified":"2023-04-29T12:39:41","modified_gmt":"2023-04-29T04:39:41","slug":"vue-reads-local-md-file","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/vue-reads-local-md-file\/","title":{"rendered":"Vue\u8bfb\u53d6\u672c\u5730md\u6587\u4ef6"},"content":{"rendered":"<p>\u4f7f\u7528 <code>$http<\/code> \u65b9\u5f0f\u83b7\u53d6<\/p>\n<pre><code>npm install vue-resource --save-dev<\/code><\/pre>\n<p><!-- more --><\/p>\n<p>news_list.vue<\/p>\n<pre><code class=\"language-html\">&lt;yd-layout style=&quot;margin-top: 10px&quot;&gt;\n  &lt;yd-cell-group title=&quot;&quot; class=&quot;demo-small-pitch&quot;&gt;\n    &lt;yd-cell-item v-for=&quot;title in titles&quot; v-bind:key=&quot;title&quot; arrow type=&quot;link&quot; v-bind:href=&quot;&#039;\/news_detail\/&#039; + title&quot;&gt;\n      &lt;span slot=&quot;left&quot;&gt;{{ title }}&lt;\/span&gt;\n    &lt;\/yd-cell-item&gt;\n  &lt;\/yd-cell-group&gt;\n&lt;\/yd-layout&gt;<\/code><\/pre>\n<p>news_detail.vue<\/p>\n<pre><code class=\"language-html\">&lt;template&gt;\n    &lt;!--&lt;div class=&quot;article&quot; v-html=&quot;compiledMarkdown&quot; v-highlight&gt;&lt;\/div&gt;--&gt;\n    &lt;vue-markdown class=&quot;article&quot; v-highlight :source=&quot;content&quot;&gt;&lt;\/vue-markdown&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nimport VueMarkdown from &#039;vue-markdown&#039;\nimport marked from &#039;marked&#039;\n\nexport default {\n  name: &#039;newsDetail&#039;,\n  data () {\n    return {\n      content: &#039;&#039;,\n      title: this.$route.params.title\n    }\n  },\n  components: {\n    &#039;vue-markdown&#039;: VueMarkdown \/\/ \u58f0\u660e\u7ec4\u4ef6\n  },\n  created () {\n    var self = this\n    this.$http.get(&#039;static\/content\/news\/&#039; + this.title + &#039;.md&#039;).then((response) =&gt; {\n      console.log(response.body)\n      self.content = response.body\n    })\n  },\n  computed: {\n    compiledMarkdown () {\n      return marked(this.content, { sanitize: true })\n    }\n  }\n}\n&lt;\/script&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528 $http \u65b9\u5f0f\u83b7\u53d6 npm install vue-resource &#8211;save-dev news_ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[170],"class_list":["post-1052","post","type-post","status-publish","format-standard","hentry","category-vue","tag-markdown"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1052"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1052\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}