wangEditor.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div>
  3. <div ref="editor"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import E from 'wangeditor';
  8. import { php_url } from "../config/env";
  9. let editor;
  10. export default {
  11. name: 'editor',
  12. data() {
  13. return {
  14. unifiedUrl: "/lexus_php/api/"
  15. };
  16. },
  17. props: ['content'],
  18. watch:{
  19. 'content':function (n) {
  20. editor.txt.html(n);
  21. }
  22. },
  23. mounted() {
  24. editor = new E(this.$refs.editor);
  25. editor.config.menus = [
  26. 'bold', // 粗体
  27. 'fontSize', // 字号
  28. 'fontName', // 字体
  29. 'italic', // 斜体
  30. 'underline', // 下划线
  31. 'strikeThrough', // 删除线
  32. // 'foreColor', // 文字颜色
  33. 'link', // 插入链接
  34. 'list', // 列表
  35. 'justify', // 对齐方式
  36. 'quote', // 引用
  37. 'image', // 插入图片
  38. 'location', // 位置
  39. ];
  40. editor.config.onchange = html => {
  41. this.$emit('input', html);
  42. };
  43. editor.config.uploadImgServer = php_url + this.unifiedUrl + 'upload.php';
  44. editor.config.uploadImgMaxSize = 10 * 1024 * 1024; // 将图片大小限制为 10M
  45. editor.config.uploadFileName = 'file'; //后端接受上传文件的参数名
  46. editor.config.uploadImgMaxLength = 1; // 限制一次最多上传 1 张图片
  47. editor.config.showLinkImg = false; //隐藏网络图片上传
  48. editor.config.uploadImgHooks = {
  49. fail: (xhr, editor, result) => {
  50. // 插入图片失败回调
  51. console.log(result);
  52. },
  53. success: (xhr, editor, result) => {
  54. // 图片上传成功回调
  55. console.log(result);
  56. },
  57. timeout: (xhr, editor) => {
  58. // 网络超时的回调
  59. console.log(xhr, editor);
  60. console.log('网络超时');
  61. },
  62. error: (xhr, editor) => {
  63. // 图片上传错误的回调
  64. console.log(xhr, editor);
  65. console.log('上传错误');
  66. },
  67. //回显
  68. customInsert: (insertImg, result) => {
  69. let url = php_url + result.full_url
  70. insertImg(url);
  71. },
  72. };
  73. editor.create();
  74. },
  75. };
  76. </script>
  77. <style>
  78. .w-e-tooltip {
  79. background-color: #fff!important;
  80. }
  81. /*.w-e-text a {*/
  82. /*color: cornflowerblue!important;*/
  83. /*}*/
  84. </style>