Nuxt+Ueditor 集成 (前后端分离项目)

  1. 下载UEditor官网jsp版本的包,下载完成解压之后得到一个utf8-jsp的文件夹:在这里插入图片描述
    除了jsp的文件夹外(jsp用于后端),其余的文件和文件夹复制到static存放静态文件的目录里面,
    在这里插入图片描述

  2. 引入 (可以在配置文件全局引,或者单独引)

    在nuxt.config.js配置文件引入:

    	script: [
          { src: '/ueditor/ueditor.config.js', type: 'text/javascript', charset: 'utf-8' },
          { src: '/ueditor/ueditor.all.min.js', type: 'text/javascript', charset: 'utf-8' },
          { src: '/ueditor/ueditor.parse.min.js', type: 'text/javascript', charset: 'utf-8' },
          { src: '/ueditor/lang/zh-cn/zh-cn.js', type: 'text/javascript', charset: 'utf-8' },
        ],
    

    注意:
    在这里插入图片描述

  3. 封装ueitor组件统一调用:
    在components文件夹下,创建Ueditor组件,复制下面代码

    <template>
      <div>
        <script id="editor" type="text/plain"></script>
      </div>
    </template>
    
    <script>
    export default {
      props: {
        id: {
          type: String,
          default: () => {
            return ''
          }
        },
        config: {
          type: Object,
          required: true,
        }
      },
      data () {
        return {
          editor: null
        }
      },
      mounted () {
        // 初始化UE
        const _this = this
        // console.log(window.UE, 'window.UE')
        this.editor = window.UE.getEditor('editor', _this.config)
      },
      methods: {
        getUEContent () {
          return this.editor.getContent()
        },
      },
      destoryed () {
        this.editor.destory()
      },
    }
    </script>
    
    

    页面调用:

    <template>
      <div class="container">
        <button @click="getTXT">获取内容</button>
        <Ueditor ref="ueditor" :config="config" />
      </div>
    </template>
    
    <script>
    import Ueditor from '~/components/Ueditor.vue'
    export default {
      components: {
        Ueditor,
      },
      data () {
        return {
          config: {}
      },
      methods: {
      	// 获取文档内容
        getTXT () {
          alert(this.$refs.ueditor.getUEContent())
        }
      }
    }
    </script>
    
    
  4. ueditor.config.js配置服务器统一请求接口路径(需要修改自己的路径)
    在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值