vue使用UEditor

博客介绍了在Vue中使用UEditor富文本编辑器的方法。包括从官网下载1.4.3.3 PHP版本的UTF - 8版本,将php版本内容添加到/static/UE/,在main.js全局引入所需文件,修改配置文件,单独定义组件,最后在父组件中使用该组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

vue使用UEditor

官网下载
[1.4.3.3 PHP版本] UTF-8版本

https://ueditor.baidu.com/website/download.html


  1. 把php版本中的内容添加到 /static/UE/
    (php 文件夹 / index.html不添加)
  2. main.js 全局引入需要的文件
    //引入UEditor需要的文件,顺序很重要
    import '../static/UE/ueditor.config'
    import '../static/UE/ueditor.all.min'
    import '../static/UE/lang/zh-cn/zh-cn'
    import '../static/UE/ueditor.parse.min'
  1. 修改 /static/UE/ueditor.config.js
    window.UEDITOR_HOME_URL = "/static/UE/";        //根目录相对路径
  1. components单独定义 UEditor.vue 组件
<template>
  <div id="UEditor">
    <script id="editor" type="text/plain"></script>
  </div>
</template>

<script>
    export default {
        name: "UEditor",
        data(){
          return{
            editor:null
          }
        },
        props:{
          defaultMsg:{type:String},
          config:{type:Object}
        },
        mounted(){
          //初始化UE
          const _this = this;
          _this.editor = UE.getEditor('editor',_this.config);
        },
        methods:{
          getUEContent(){
            //获取内容方法
            return this.editor.getUEContent()
          }
        },
        destoryed(){
          this.editor.destory();
        }
    }
</script>

  1. 父组件中使用UEditor组件
<template>
  <div class="docMain">
    <UEditor :config=config ref="ue"></UEditor>
  </div>
</template>

<script>
    import UEditor from '../components/UEditor'
    export default {
        name: "test",
        data(){
          return{
            config:{
              initialFrameWidth:900,
              initialFrameHeight:650
            },
            docTitle:"",
            docDescription:"",
            docMain:"",
          }
        },
        components:{
          UEditor
        }
    }
</script>
### 集成 UEditor 富文本编辑器Vue 项目 #### 下载并准备 UEditor Puls 为了在 Vue 项目中集成 UEditor,首先需要从指定仓库下载 UEditor Plus 的代码[^1]: ```plaintext https://gitee.com/modstart-lib/ueditor-plus/tree/master ``` 解压下载的压缩包后,将 `dist` 文件夹内的内容重命名为 `UEditor` 并放置于 Vue 项目的 `public` 目录下。 #### 安装依赖项 接着安装必要的 NPM 包来支持 UEditor 组件的工作: ```bash npm install vue-ueditor-wrap --save ``` 此命令会自动更新 `package.json` 文件并将所需模块加入至开发环境中。 #### 注册组件 为了让整个应用程序能够访问 UEditor 编辑器, 可以选择全局注册该组件。这通常是在应用入口文件 `main.js` 中完成的操作: ```javascript import VueUeditorWrap from 'vue-ueditor-wrap'; Vue.component('VueUeditorWrap', VueUeditorWrap); ``` 这段代码使得 `<vue-ueditor-wrap>` 成为可用标签,在任何模板内都可以直接调用它而无需单独导入。 #### 使用组件 现在可以在任意 `.vue` 文件中像下面这样使用新创建好的自定义元素了: ```html <template> <div id="app"> <!-- ...其他HTML结构... --> <vue-ueditor-wrap v-model="content"></vue-ueditor-wrap> <!-- ...更多HTML结构... --> </div> </template> <script> export default { data() { return { content: '' }; } }; </script> ``` 这里假设有一个名为 `content` 的数据属性用来绑定编辑区的内容变化情况。每当用户输入或修改文字时,这些更改都会反映在这个变量上面。 对于更详细的配置选项以及高级功能(比如图片上传),建议查阅官方文档获得最新最全的信息[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值