123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <template>
- <div>
- <div :id="this.id"></div>
- </div>
- </template>
-
- <script>
-
-
- export default {
- name: 'Editor',
- props: ['id', 'r_content'],
- data() {
- return {
- ue: '', //ueditor实例
- content: '' //编辑器内容
- }
- },
- methods: {
- //初始化编辑器
- initEditor() {
- this.ue = UE.getEditor(this.id, {
- initialFrameWidth: '100%',
- initialFrameHeight: '600',
- topOffset: '110',
- toolbars: [[
- 'bold', //加粗
- 'underline', //下划线
- 'justifyleft', //居左对齐
- 'justifycenter', //居中对齐
- 'justifyright', //居右对齐
- 'justifyjustify', //两端对齐
- 'formatmatch', //格式刷
- 'fontsize', //字体大小
- 'fontfamily', //字体
- 'forecolor', //字体颜色
- 'insertrow',//前插入行
- 'inserttable', //插入表格
- 'edittable', //表格属性
- 'edittd', //单元格属性
- 'mergeright', //右合并单元格
- 'mergedown', //下合并单元格
- 'deleterow', //删除行
- 'deletecol', //删除列
- 'splittorows', //拆分成行
- 'splittocols', //拆分成列
- 'splittocells', //完全拆分单元格
- 'deletecaption', //删除表格标题
- 'deletetable', //删除表格
- 'mergecells', //合并多个单元格
- ]]
- // scaleEnabled: true,
- })
- //编辑器准备就绪后会触发该事件
- this.ue.addListener('ready', () => {
- //设置可以编辑
- this.ue.setEnabled()
- this.ue.setContent(this.r_content)
- })
- //编辑器内容修改时
- this.selectionchange()
- },
-
- //编辑器内容修改时
- selectionchange() {
- this.ue.addListener('selectionchange', () => {
- this.content = this.ue.getContent()
- })
- }
-
- },
-
- activated() {
- //初始化编辑器
- this.initEditor()
- },
- deactivated() {
- //销毁编辑器实例,使用textarea代替
- this.ue.destroy()
- //重置编辑器,可用来做多个tab使用同一个编辑器实例
- //this.ue.reset()
- //如果要使用同一个实例,请注释destroy()方法
- },
-
- computed: {
- // 利用计算属性返回prop里传过来的内容
- revecive: function() {
- return this.r_content
- }
- },
-
- watch: {
- // !!! 这里需要注意,需要一个watch来实时更新编辑器的内容
- revecive: function() {
- this.ue.setContent(this.r_content)
- }
- }
- }
- </script>
-
-
- <style>
- .edui-editor {
- z-index: 60 !important;
- }
- #edui_fixedlayer{
- z-index: 5000 !important;
- }
- </style>
|