1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Nuxtにマークダウンエディタを埋め込む

Posted at

vue-simplemde
というものをありがたく使わせていただき、マークダウンエディタを埋め込んでみる。

インストール

npm install vue-simplemde --save

plugins配下にnuxt-simplemde-plugin.js作成

nuxt-simplemde-plugin.js
import Vue from 'vue'
import VueSimplemde from 'vue-simplemde'
import 'simplemde/dist/simplemde.min.css'

Vue.component('vue-simplemde', VueSimplemde)

nuxt.config.jsに追加

nuxt.config.js
module.exports = {
   // some nuxt config...
   plugins: [
     { src: '~plugins/nuxt-simplemde-plugin.js', mode: 'client' },
   ],
   css: [
     'simplemde/dist/simplemde.min.css',
   ],
};

コンポーネントで使用する

main.vue
<template>
   <div class="wrap">
     <client-only>
       <vue-simplemde v-model="content" />
     </client-only>
   </div>
</template>

<script>
export default {
   data() {
     return {
       content: ''
     }
   }
}
</script>

マークダウンエディタのカスタマイズ

マークダウンエディタのカスタマイズなどはconfigで設定できる。
設定項目の詳細についてはこちら

main.vue
<template>
   <div class="wrap">
     <client-only>
       <vue-simplemde v-model="content" :configs="configs" />
     </client-only>
   </div>
</template>

<script>
export default {
   data:() =>( {
       content: '',
       configs: {
         autosave: {
           enabled: false
         },
         initialValue: '',
         toolbar: [
           'preview',
           '|',
           'bold',
           'italic',
           'heading',
           'heading-smaller',
           'heading-bigger',
           '|',
           'code',
           'quote',
           'link',
           '|',
           'unordered-list',
           'ordered-list',
           'table',
           'horizontal-rule',
           '|',
           'guide'
         ]
       }
   })
}
</script>
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?