首页 > 其他 > 详细

nuxt整合mavon-editor(markdown富文本编辑器)

时间:2021-04-01 00:34:22      阅读:82      评论:0      收藏:0      [点我收藏+]
1、npm i -S mavon-editor
2、plugins新建mavon-editor.js
    import Vue from vue
    import mavonEditor from mavon-editor
    
    Vue.use(mavonEditor)
3、配置nuxt.config.js
    css: [
        mavon-editor/dist/css/index.css
    ],
    plugins: [
        {src: @/plugins/mavon-editor.js, mode: client},
    ],
4、使用
<template>
  <div>
    <!--
    :autofocus="false":不自动获取焦点
    @change="getMdHtml":内容改变事件
    @imgAdd="uploadContentImg":操作栏上传文件事件
    @imgDel="delConentImg":操作栏删除文件事件
    -->
    <mavon-editor :autofocus="false" ref="md" v-model="mdContent" @change="getMdHtml"
                  @imgAdd="uploadContentImg" @imgDel="delConentImg"/>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        mdContent: "",
        htmlContent: ""
      }
    },
    methods: {
      getMdHtml(mdContent, htmlContent) {//参数1:md语法内容,参数2:html语法内容
        this.htmlContent = htmlContent
      },
      uploadContentImg(pos, file) {
        const fd = new FormData()
        fd.append(file, file)
        this.$uploadImg(fd).then(response => {//上传图片接口
          if (response.code === 20000) {
            this.$refs.md.$img2Url(pos, response.data)//图片索引替换为url
          }
        })
      },
      delConentImg(urlAndFileArr) {
        const fileUrl = urlAndFileArr[0]
        const file = urlAndFileArr[1]
        this.$deleteImg(fileUrl)//删除图片接口
      }
    }
  }
</script>

<style scoped>
</style>

 

nuxt整合mavon-editor(markdown富文本编辑器)

原文:https://www.cnblogs.com/linding/p/14604073.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!