"_blank" href="https://github.com/suweiteng/vue2-management-platform" rel="external nofollow" >https://github.com/suweiteng/vue2-management-platform 

1.放入静态资源并配置

首先把官网下载的Ueditor资源,放入静态资源src/static中。

vue2.0项目中使用Ueditor富文本编辑器示例代码

 修改ueditor.config.js中的window.UEDITOR_HOME_URL配置,如下图:

vue2.0项目中使用Ueditor富文本编辑器示例代码

2.引入

在main.js中引入

import '../static/UE/ueditor.config.js'
import '../static/UE/ueditor.all.min.js'
import '../static/UE/lang/zh-cn/zh-cn.js'
import '../static/UE/ueditor.parse.min.js'

3.开发公共组件

开发公共组件,可设置填充内容defaultMsg,配置信息config(宽度和高度等),并提供获取内容的方法。

<template>
 <div>
  <script id="editor" type="text/plain"></script>
 </div>
</template>
<script>
 export default {
  name: 'UE',
  data () {
   return {
    editor: null
   }
  },
  props: {
   defaultMsg: {
    type: String
   },
   config: {
    type: Object
   }
  },
  mounted() {
   const _this = this;
   this.editor = UE.getEditor('editor', this.config); // 初始化UE
   this.editor.addListener("ready", function () {
    _this.editor.setContent(_this.defaultMsg); // 确保UE加载完成后,放入内容。
   });
  },
  methods: {
   getUEContent() { // 获取内容方法
    return this.editor.getContent()
   }
  },
  destroyed() {
   this.editor.destroy();
  }
 }
</script>

4.使用

当我们需要使用富文本编辑器时,直接调用公共组件即可

<template>
 <div class="components-container">
  <div class="info">UE编辑器示例<br>需要使用编辑器时,调用UE公共组件即可。可设置填充内容defaultMsg,配置信息config(宽度和高度等),可调用组件中获取内容的方法。</div>
  <button @click="getUEContent()">获取内容</button>
  <div class="editor-container">
   <UE :defaultMsg=defaultMsg :config=config ref="ue"></UE>
  </div>
 </div>
</template>
<style>
 .info{
  border-radius: 10px;
  line-height: 20px;
  padding: 10px;
  margin: 10px;
  background-color: #ffffff;
 }
</style>
<script>
 import UE from '../../components/ue/ue.vue';
 export default {
  components: {UE},
  data() {
   return {
    defaultMsg: '这里是UE测试',
    config: {
     initialFrameWidth: null,
     initialFrameHeight: 350
    }
   }
  },
  methods: {
   getUEContent() {
    let content = this.$refs.ue.getUEContent();
    this.$notify({
     title: '获取成功,可在控制台查看!',
     message: content,
     type: 'success'
    });
    console.log(content)
   }
  }
 };
</script>

效果如下:

vue2.0项目中使用Ueditor富文本编辑器示例代码

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。