• vue使用UEditor富文本编辑器[实用]


    前后分离的东西,在图片上传 文章发布这块还是挺那个的,发现很少完整的UEditorvue的demo.今天这个记录一下.

    demo 请狠狠的戳这里 ¥ http://download.lllomh.com/cliect/#/product/J417120073092956

    demo 请狠狠的戳这里 c https://download.csdn.net/download/lllomh/11485763

    其实也差不多,把配置拿出来了而已,放在vue里面了!

    将编辑器封装成组件的方式,方便调用,代码如下:

    <template>
      <div>
        <script id="editor" type="text/plain" ></script>
      </div>
    </template>
    
    <script>
      import AppConfig from '@/config'
      import '../../../../../../static/ueditor/ueditor.config.js'
      import '../../../../../../static/ueditor/ueditor.all.js'
      import '../../../../../../static/ueditor/lang/zh-cn/zh-cn.js'
    
      export default {
        name: "UEditor",
        props: {
          id: {
              type: String
          },
          config: {
              type: Object
          }
        },
        data() {
          return {
            editor: null
          }
        },
        mounted() {
          //初始化UE
          const _this = this;
          this.editor = UE.getEditor('editor',this.config);
        },
        destoryed() {
          this.editor.destory();
        },
        methods:{
          getUEContent: function(){
           return this.editor.getContent();
          }
        }
      }
    </script>

    导出 组件:

    var UEditor =  require('./src/ueditor.vue');
    
    
    module.exports = {
      UEditor
    }

    页面调用:

    <template>
      <div id="app" class="hello">
        <el-button size="primary" type="info" icon="plus" @click="openWindow">打开窗口</el-button>
        <el-dialog title="新增菜单" size="small" v-model="addFormVisible" :close-on-click-modal="false">
          <div>
            <el-button size="primary" type="info" icon="plus" @click="getContent">获取内容</el-button>
            <UEditor :config=config ref="ueditor"></UEditor>
          </div>
        </el-dialog>
    
      </div>
    </template>
    
    <script>
      import {UEditor} from './ueditor/index.js'
    
      export default{
          name: 'hello',
          components: {UEditor},
          data(){
            return {
              config: {
                /*//可以在此处定义工具栏的内容
                toolbars: [
                  ['fullscreen', 'source','|', 'undo', 'redo','|','bold', 'italic', 'underline', 'fontborder', 'strikethrough',
                    '|','superscript','subscript','|', 'forecolor', 'backcolor','|', 'removeformat','|', 'insertorderedlist', 'insertunorderedlist',
                    '|','selectall', 'cleardoc','fontfamily','fontsize','justifyleft','justifyright','justifycenter','justifyjustify','|',
                    'link','unlink']
                ],*/
                serverUrl:P_UEDIT,//配置地址
                autoHeightEnabled: false,
                autoFloatEnabled: true,  //是否工具栏可浮动
                initialContent:'请输入内容',   //初始化编辑器的内容,也可以通过textarea/script给值,看官网例子
                autoClearinitialContent:true, //是否自动清除编辑器初始内容,注意:如果focus属性设置为true,这个也为真,那么编辑器一上来就会触发导致初始化的内容看不到了
                initialFrameWidth: null,
                initialFrameHeight: 450,
                BaseUrl: '',
                UEDITOR_HOME_URL: 'static/ueditor/'
              },
              addFormVisible: false
            }
          },
          methods: {
            openWindow: function(){
                this.addFormVisible = true;
            },
            //获取文档内容
            getContent: function(){
              let content = this.$refs.ueditor.getUEContent();
              console.log(content);
              alert(content);
            }
          }
      }
    
    </script>

    ueditor.config 中的 服务url  可以清空 :

    在调用的时候传入  serverUrl 就好。

    配置 跟 pc 的一样的 重点还是那个配置地址,剩下的就是后台的事情了.

  • 相关阅读:
    C#中 Thread,Task,Async/Await,IAsyncResult 的那些事儿!
    Java8的新特性以及与C#的比较
    点旋转坐标变换
    vc++返回模块路径
    为什么不要 "lock(this)" ? lock object 并是readonly(转载)
    《黄帝内经》要义
    C++多线程编程简单实例
    c++ 获取文件大小
    c# 获取文件夹大小
    自动驾驶仿真工具的下载与安装
  • 原文地址:https://www.cnblogs.com/lllomh/p/14991909.html
Copyright © 2020-2023  润新知