html 组件化 编辑器,vue.js组件化使用百度富文本编辑器(一)

注意:html

本文采用的编辑器为:ideavue

1.下载百度富文本编辑器,地址:https://ueditor.baidu.com/website/download.html#ueditorweb

2.加入到static文件夹下,如图:npm

a98328b87f4c48d3b44670f231eaa59a.gif

3.在main.js中引入js。编辑器

a98328b87f4c48d3b44670f231eaa59a.gif

注意:必定要修改ueditor.config.js中的路径ide

window.UEDITOR_HOME_URL = "./static/ueditor/"

a98328b87f4c48d3b44670f231eaa59a.gif

4.编写vue组件:学习

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();

}

}

5.编写测试使用的Vue界面:

获取内容

//采用局部引用的方式注册组件

import ueditor from '@/components/Ueditor';

export default {

name: "PublishPage",

data() {

return {

defaultMsg: '说点什么吧',

config: {

initialFrameWidth: null,

initialFrameHeight: 350

}

}

},

components: {

ueditor

},

methods: {

getUEContent() {

let content = this.$refs.ue.getUEContent();

this.$notify({

title: '获取成功,可在控制台查看!',

message: content,

type: 'success'

});

console.log(content)

}

}

}

6.编写路由

a98328b87f4c48d3b44670f231eaa59a.gif

7.运行项目测试

npm run devthis

8.效果展现idea

a98328b87f4c48d3b44670f231eaa59a.gif

注:

1.编写的文本和媒体文件发送到服务端请看下一篇介绍。

2.这是笔者学习记录的过程,若是有错误,敬请指正,不喜勿喷,谢谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值