markdown.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <div class="components-container">
  3. <aside>Markdown is based on
  4. <a href="https://github.com/nhnent/tui.editor" target="_blank">tui.editor</a> ,simply wrapped with Vue.
  5. <a
  6. target="_blank"
  7. href="https://panjiachen.github.io/vue-element-admin-site/feature/component/markdown-editor.html"
  8. >
  9. Documentation </a>
  10. </aside>
  11. <div class="editor-container">
  12. <el-tag class="tag-title">
  13. Basic:
  14. </el-tag>
  15. <markdown-editor v-model="content1" height="300px" />
  16. </div>
  17. <div class="editor-container">
  18. <el-tag class="tag-title">
  19. Markdown Mode:
  20. </el-tag>
  21. <markdown-editor ref="markdownEditor" v-model="content2" :options="{hideModeSwitch:true,previewStyle:'tab'}" height="200px" />
  22. </div>
  23. <div class="editor-container">
  24. <el-tag class="tag-title">
  25. Customize Toolbar:
  26. </el-tag>
  27. <markdown-editor v-model="content3" :options="{ toolbarItems: ['heading','bold','italic']}" />
  28. </div>
  29. <div class="editor-container">
  30. <el-tag class="tag-title">
  31. I18n:
  32. </el-tag>
  33. <el-alert
  34. :closable="false"
  35. title="You can change the language of the admin system to see the effect"
  36. type="success"
  37. />
  38. <markdown-editor ref="markdownEditor" v-model="content4" :language="language" height="300px" />
  39. </div>
  40. <el-button style="margin-top:80px;" type="primary" icon="el-icon-document" @click="getHtml">
  41. Get HTML
  42. </el-button>
  43. <div v-html="html" />
  44. </div>
  45. </template>
  46. <script>
  47. import MarkdownEditor from '@/components/MarkdownEditor'
  48. const content = `
  49. **This is test**
  50. * vue
  51. * element
  52. * webpack
  53. `
  54. export default {
  55. name: 'MarkdownDemo',
  56. components: { MarkdownEditor },
  57. data() {
  58. return {
  59. content1: content,
  60. content2: content,
  61. content3: content,
  62. content4: content,
  63. html: '',
  64. languageTypeList: {
  65. 'en': 'en_US',
  66. 'zh': 'zh_CN',
  67. 'es': 'es_ES'
  68. }
  69. }
  70. },
  71. computed: {
  72. language() {
  73. return this.languageTypeList[this.$store.getters.language]
  74. }
  75. },
  76. methods: {
  77. getHtml() {
  78. this.html = this.$refs.markdownEditor.getHtml()
  79. console.log(this.html)
  80. }
  81. }
  82. }
  83. </script>
  84. <style scoped>
  85. .editor-container{
  86. margin-bottom: 30px;
  87. }
  88. .tag-title{
  89. margin-bottom: 5px;
  90. }
  91. </style>