vue项目中使用vue-ueditor-wrap

1.安装 插件

npm install vue-ueditor-wrap

2. UEditor 并不支持通过 npm 的方式来安装,vue-ueditor-wrap 也只是一个 Vue 组件,组件本身并不是 UEditor 的 Vue 版。了解 UEditor 基本使用,请参考 UEditor 官网。(我下载的是 php 版本)

将解压的文件夹重命名为 UEditor 并移动到你项目的静态资源目录下,比如下面是一个由 Vue CLI(v3+)创建的项目,静态资源目录就是 public。

3.使用

<script>
//引入VueUeditorWrap组件
import VueUeditorWrap from 'vue-ueditor-wrap'; // ES6 Module
//注册组件 
components: {
  VueUeditorWrap;
}

</script>

 4.v-model绑定数据

<vue-ueditor-wrap v-model="content" :config="config" ref="ueditor" @ready="ready"></vue-ueditor-wrap>


<script>
 data(){
    return {
        config: {
          // 相对路径
          UEDITOR_HOME_URL: '/UEditor/',
          // 编辑器不自动被内容撑高
          autoHeightEnabled: false,
          // 初始容器高度// 初始容器宽度
          initialFrameHeight: 300,
          initialFrameWidth: '100%',
          toolbars: [[
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
            'directionalityltr', 'directionalityrtl', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
            'simpleupload', 'insertimage', '|',
            'horizontal', 'date', 'time', 'spechars', 'snapscreen', '|',
            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts'
          ]],
          // 不显示字数
          // wordCount: false,
          enableAutoSave:true,//自动保存
          // 上传图片路径,需要后台配置,否则控制台会报错。   
          // 报错信息为 后台配置项返回格式出错,上传功能将不能正常使用!
          serverUrl: 'http://35.201.165.105:8000/controller.php'
         
        },
     
    }
 }
</script>

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
Vue-UEditor-Wrap 是一个基于 Vue.js 的富文本编辑器封装组件,它集成了百度 UEditor 编辑器。它可以帮助开发者在 Vue 项目方便地使用 UEditor 编辑器,并提供了一些自定义配置和事件回调。通过 Vue-UEditor-Wrap,开发者可以快速实现富文本编辑功能,例如编辑文章、发布评论等。 该组件的使用方式很简单,首先需要安装 Vue-UEditor-Wrap 包,然后在项目引入它。在 Vue 组件,可以使用 `<vue-ueditor-wrap>` 标签来渲染编辑器,并配置相应的属性和方法。 以下是一个简单的示例: ```html <template> <vue-ueditor-wrap :config="editorConfig" @ready="handleEditorReady" @content-change="handleContentChange" ></vue-ueditor-wrap> </template> <script> import VueUeditorWrap from 'vue-ueditor-wrap'; export default { components: { VueUeditorWrap, }, data() { return { editorConfig: { // 配置项... }, }; }, methods: { handleEditorReady() { // 编辑器初始化完成后的回调函数 }, handleContentChange(content) { // 编辑器内容变化时的回调函数 }, }, }; </script> ``` 通过配置 `editorConfig` 对象,可以设置 UEditor 的相关配置项,如工具栏按钮、字体、颜色等。在 `handleEditorReady` 方法,可以执行一些初始化操作,比如设置编辑器的内容。而 `handleContentChange` 方法会在编辑器内容变化时触发,可以获取最新的编辑器内容。 希望这能解答你的问题!如有更多疑问,请继续提问。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值