|
@@ -21,52 +21,57 @@
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
|
- const editor = new wangEditor(`#wangEditorId`);
|
|
|
- // 配置 onchange 回调函数,将数据同步到 vue 中
|
|
|
- editor.config.onchange = (newHtml) => {
|
|
|
- this.editorData = newHtml;
|
|
|
- this.$emit("editorContent", newHtml);
|
|
|
- };
|
|
|
- editor.config.uploadImgServer = settings.apiUrl + '/file/upload'
|
|
|
- editor.config.uploadFileName = 'files';
|
|
|
- editor.config.uploadImgHooks = {
|
|
|
- // 图片上传并返回了结果,图片插入已成功
|
|
|
- success: function (xhr) {
|
|
|
- console.log('success', xhr)
|
|
|
- },
|
|
|
- // 图片上传并返回了结果,但图片插入时出错了
|
|
|
- fail: function (xhr, editor, resData) {
|
|
|
- console.log('fail', resData)
|
|
|
- this.$message.error("文件上传失败")
|
|
|
- },
|
|
|
- // 上传图片出错,一般为 http 请求的错误
|
|
|
- error: function (xhr, editor, resData) {
|
|
|
- console.log('error', xhr, resData)
|
|
|
- this.$message.error("文件上传失败")
|
|
|
- },
|
|
|
- // 上传图片超时
|
|
|
- timeout: function (xhr) {
|
|
|
- console.log('timeout')
|
|
|
- },
|
|
|
- // 图片上传并返回了结果,想要自己把图片插入到编辑器中
|
|
|
- // 例如服务器端返回的不是 { errno: 0, data: [...] } 这种格式,可使用 customInsert
|
|
|
- customInsert: function (insertImgFn, result) {
|
|
|
- if (result.data.length > 0) {
|
|
|
- // insertImgFn 可把图片插入到编辑器,传入图片 src ,执行函数即可
|
|
|
- insertImgFn(result.data[0].url)
|
|
|
- } else {
|
|
|
- this.$message.error("文件上传失败")
|
|
|
- }
|
|
|
- // result 即服务端返回的接口
|
|
|
- console.log('customInsert', result)
|
|
|
- }
|
|
|
- };
|
|
|
- // 创建编辑器
|
|
|
- editor.create();
|
|
|
- editor.txt.html(this.value)
|
|
|
- this.editor = editor;
|
|
|
+ setTimeout(() => {
|
|
|
+ this.init()
|
|
|
+ })
|
|
|
},
|
|
|
methods: {
|
|
|
+ init(){
|
|
|
+ const editor = new wangEditor(`#wangEditorId`);
|
|
|
+ // 配置 onchange 回调函数,将数据同步到 vue 中
|
|
|
+ editor.config.onchange = (newHtml) => {
|
|
|
+ this.editorData = newHtml;
|
|
|
+ this.$emit("editorContent", newHtml);
|
|
|
+ };
|
|
|
+ editor.config.uploadImgServer = settings.apiUrl + '/file/upload'
|
|
|
+ editor.config.uploadFileName = 'files';
|
|
|
+ editor.config.uploadImgHooks = {
|
|
|
+ // 图片上传并返回了结果,图片插入已成功
|
|
|
+ success: function (xhr) {
|
|
|
+ console.log('success', xhr)
|
|
|
+ },
|
|
|
+ // 图片上传并返回了结果,但图片插入时出错了
|
|
|
+ fail: function (xhr, editor, resData) {
|
|
|
+ console.log('fail', resData)
|
|
|
+ this.$message.error("文件上传失败")
|
|
|
+ },
|
|
|
+ // 上传图片出错,一般为 http 请求的错误
|
|
|
+ error: function (xhr, editor, resData) {
|
|
|
+ console.log('error', xhr, resData)
|
|
|
+ this.$message.error("文件上传失败")
|
|
|
+ },
|
|
|
+ // 上传图片超时
|
|
|
+ timeout: function (xhr) {
|
|
|
+ console.log('timeout')
|
|
|
+ },
|
|
|
+ // 图片上传并返回了结果,想要自己把图片插入到编辑器中
|
|
|
+ // 例如服务器端返回的不是 { errno: 0, data: [...] } 这种格式,可使用 customInsert
|
|
|
+ customInsert: function (insertImgFn, result) {
|
|
|
+ if (result.data.length > 0) {
|
|
|
+ // insertImgFn 可把图片插入到编辑器,传入图片 src ,执行函数即可
|
|
|
+ insertImgFn(result.data[0].url)
|
|
|
+ } else {
|
|
|
+ this.$message.error("文件上传失败")
|
|
|
+ }
|
|
|
+ // result 即服务端返回的接口
|
|
|
+ console.log('customInsert', result)
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // 创建编辑器
|
|
|
+ editor.create();
|
|
|
+ editor.txt.html(this.value)
|
|
|
+ this.editor = editor;
|
|
|
+ },
|
|
|
getEditorData() {
|
|
|
// 通过代码获取编辑器内容
|
|
|
let data = this.editor.txt.html();
|
|
@@ -82,6 +87,7 @@
|
|
|
</script>
|
|
|
|
|
|
<style lang="css" scoped>
|
|
|
+
|
|
|
.home {
|
|
|
width: 100%;
|
|
|
margin: auto;
|