index.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <div class="markdown-editor-container">
  3. <el-row :gutter="20">
  4. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
  5. <vab-markdown-editor
  6. ref="mde"
  7. v-model="value"
  8. @show-html="handleShowHtml"
  9. ></vab-markdown-editor>
  10. <el-button @click="handleAddText">增加文本</el-button>
  11. <el-button @click="handleAddImg">增加图片</el-button>
  12. </el-col>
  13. <el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
  14. <el-card shadow="hover">
  15. <div slot="header">
  16. <span>markdown转换html实时演示区域</span>
  17. </div>
  18. <div v-html="html"></div>
  19. </el-card>
  20. </el-col>
  21. </el-row>
  22. </div>
  23. </template>
  24. <script>
  25. import VabMarkdownEditor from '@/plugins/vabMarkdownEditor'
  26. export default {
  27. name: 'MarkdownEditor',
  28. components: { VabMarkdownEditor },
  29. data() {
  30. return {
  31. value: '# vue-admin-beautiful',
  32. html: '<h1 id="vue-admin-beautiful">vue-admin-beautiful</h1>',
  33. }
  34. },
  35. methods: {
  36. handleAddText() {
  37. this.$refs.mde.add('\n### 新增加的内容')
  38. },
  39. handleAddImg() {
  40. this.$refs.mde.add(
  41. '\n![](https://gitee.com/chu1204505056/image/raw/master/qq_group/vab-2.png)'
  42. )
  43. },
  44. handleShowHtml(html) {
  45. this.html = html
  46. },
  47. },
  48. }
  49. </script>