国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

react hook使用UEditor引入秀米圖文排版

這篇具有很好參考價(jià)值的文章主要介紹了react hook使用UEditor引入秀米圖文排版。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

里面坑比較多,細(xì)節(jié)也比較多

以下使用的是react 18 + ice3.0,使用其他react腳手架的配置基本相同,例如umi4

1.下載UEditor

進(jìn)入U(xiǎn)Editor倉(cāng)庫(kù),找到版本v1.4.3.3,點(diǎn)擊進(jìn)去
react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架
接著下載ueditor1_4_3_3-utf8-jsp.zip版本

react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架
下載好以后開(kāi)始安裝依賴:npm install ,依賴安裝完成后就可以打包了,最終我們項(xiàng)目要的就是這個(gè)打包后的文件。

打包需要使用grunt:

  • 全局安裝npm install -g grunt-cli
  • 在項(xiàng)目ueditor中安裝grunt依賴,npm install grunt --save-dev
  • 在項(xiàng)目ueditor輸入指令grunt default來(lái)生成一個(gè)dist文件
    react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架

2.react項(xiàng)目配置UEditor

react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架
復(fù)制dist\utf8-php下的所有文件到react項(xiàng)目中的public\editor\ueditor下面(沒(méi)有這個(gè)目錄就新建一個(gè))。
如下,注意標(biāo)黃的文件是后面步驟加上的,沒(méi)有這個(gè)文件是正常的:react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架
接著引入U(xiǎn)Editor

找到src\document.tsx文件,就這個(gè)文件就相當(dāng)于其他項(xiàng)目中的index.html,具體使用參考document定制html,在這里引入U(xiǎn)Editor,我們的文件存放的地址在public下面,這里寫(xiě)路徑的時(shí)候不用寫(xiě)public,直接從editor開(kāi)始寫(xiě),/editor/ueditor/ueditor.config.js/editor/ueditor/ueditor.all.js
react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架

注意?。∪绻憔庉嬈鲌?bào)錯(cuò),放開(kāi)下面兩個(gè)注釋的文件

3.react組件引入U(xiǎn)Editor

新建src\components\ReactUeditor文件夾,分別以下幾個(gè)文件
react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架

index.tsx

import React, { useEffect, useImperativeHandle, forwardRef } from "react";
let editor: any = null;
function UEditor(props, ref) {
  useEffect(() => {
    if (window.UE.getEditor) {
      setConfig(props.initData, props.config, props.setContent);
    }
    return () => {
      editor.destroy(props.id);
      // 組件銷(xiāo)毀時(shí)候移除頁(yè)面中id的textarea
      let tagElement = window.document.querySelector(`#ueditor-container`);
      tagElement?.parentElement?.removeChild(tagElement);
      // editor.removeListener(); //不要打開(kāi),否則返回有問(wèn)題報(bào)錯(cuò)
    };
  }, []);

  // 初始化編輯器
  const setConfig = (initData, config, setContent) => {
    editor =
      window.UE &&
      window.UE.getEditor("ueditor-container", {
        // toolbars,
        // enableAutoSave: false,
        maximumWords: 1000000,
        scaleEnabled: false,
        autoFloatEnabled: false,
        autoHeightEnabled: false,
        initialFrameHeight: (config && config.initialFrameHeight) || 450,
		initialFrameWidth: (config && config.initialFrameWidth) || "100%",
        zIndex: 1,
      });
    editor.ready(() => {
      if (initData) {
        editor.setContent(initData); // 設(shè)置默認(rèn)值/表單回顯
      }
    });
    editor.addListener("blur", function () {
      setContent(editor.getContent());
    });
  };
  // 暴露方法
  useImperativeHandle(ref, () => ({
    getUEContent: () => {
      return editor.getContent(); // 獲取編輯器內(nèi)容
    },
  }));
  return <script id="ueditor-container" type="text/plain" />;
}
export default forwardRef(UEditor);

頁(yè)面組件引入

import ReactUeditor from "@/components/ReactUeditor";

<Form.Item name="contents">
    <ReactUeditor onChange={onChange}
              autoFloatEnabled={type !== "detail" ? true : false}
              initData={initData}
              setContent={(val) => console.log(val)}></ReactUeditor>
</Form.Item>

這個(gè)時(shí)候就能看到效果了
react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架

4.接入秀米

參考地址

引入秀米圖標(biāo)和樣式
react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架
xiumi-ue-dialog-v5.js

/**
 * Created by shunchen_yang on 16/10/25.
 */

UE.registerUI("dialog", function (editor, uiName) {
  var btn = new UE.ui.Button({
    name: "/* xiumi-connect */",
    title: "秀米",
    onclick: function () {
      var dialog = new UE.ui.Dialog({
        iframeUrl: "/editor/ueditor/xiumi-ue-dialog-v5.html",
        editor: editor,
        name: "xiumi-connect",
        title: "秀米圖文消息助手",
        cssRules:
          "width: " +
          (window.innerWidth - 80) +
          "px;" +
          "height: " +
          (window.innerHeight - 280) +
          "px;z-index:100000",
      });
      dialog.render();
      dialog.open();
    },
  });
  return btn;
});

xiumi-ue-v5.css

.edui-button.edui-for-xiumi-connect .edui-button-wrap .edui-button-body .edui-icon {
    background-image: url("./xiumi-connect-icon.png") !important;
    background-size: contain;
}

通過(guò)iframe 嵌入秀米
react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架

internal.js

(function () {
  var parent = window.parent;
  //dialog對(duì)象
  dialog = parent.$EDITORUI[window.frameElement.id.replace(/_iframe$/, "")];
  //當(dāng)前打開(kāi)dialog的編輯器實(shí)例
  editor = dialog.editor;

  UE = parent.UE;

  domUtils = UE.dom.domUtils;

  utils = UE.utils;

  browser = UE.browser;

  ajax = UE.ajax;

  $G = function (id) {
    return document.getElementById(id);
  };
  //focus元素
  $focus = function (node) {
    setTimeout(function () {
      if (browser.ie) {
        var r = node.createTextRange();
        r.collapse(false);
        r.select();
      } else {
        node.focus();
      }
    }, 0);
  };
  utils.loadFile(document, {
    href:
      editor.options.themePath +
      editor.options.theme +
      "/dialogbase.css?cache=" +
      Math.random(),
    tag: "link",
    type: "text/css",
    rel: "stylesheet",
  });
  lang = editor.getLang(dialog.className.split("-")[2]);
if (lang) {
    domUtils.on(window, "load", function () {
      var langImgPath =
        editor.options.langPath + editor.options.lang + "/images/";
      //針對(duì)靜態(tài)資源
      for (var i in lang["static"]) {
        var dom = $G(i);
        if (!dom) continue;
        var tagName = dom.tagName,
          content = lang["static"][i];
        if (content.src) {
          //clone
          content = utils.extend({}, content, false);
          content.src = langImgPath + content.src;
        }
        if (content.style) {
          content = utils.extend({}, content, false);
          content.style = content.style.replace(
            /url\s*\(/g,
            "url(" + langImgPath
          );
        }
        switch (tagName.toLowerCase()) {
          case "var":
            dom.parentNode.replaceChild(document.createTextNode(content), dom);
            break;
          case "select":
            var ops = dom.options;
                 for (var j = 0, oj; (oj = ops[j]); ) {
              oj.innerHTML = content.options[j++];
            }
            for (var p in content) {
              p != "options" && dom.setAttribute(p, content[p]);
            }
            break;
          default:
            domUtils.setAttributes(dom, content);
        }
      }
    });
  }
})();

xiumi-ue-dialog-v5.html

<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>XIUMI connect</title>
    <style>
        html,
        body {
            padding: 0;
            margin: 0;
        }

        #xiumi {
            position: absolute;
            width: 100%;
            height: 100%;
            border: none;
            box-sizing: border-box;
        }
    </style>
</head>

<body>
    <iframe id="xiumi" src="https://xiumi.us/studio/v5#/paper">
    </iframe>
    <script type="text/javascript" src="dialogs/internal.js"></script>
    <script>
        var xiumi = document.getElementById('xiumi');
        var xiumi_url = "https://xiumi.us";
        console.log("xiumi_url is %o", xiumi_url);
        xiumi.onload = function () {
            console.log("postMessage to %o", xiumi_url);
            // "XIUMI:3rdEditor:Connect" 是特定標(biāo)識(shí)符,不能修改,大小寫(xiě)敏感
 			xiumi.contentWindow.postMessage('XIUMI:3rdEditor:Connect', xiumi_url);
        };
        document.addEventListener("mousewheel", function (event) {
            event.preventDefault();
            event.stopPropagation();
        });
        window.addEventListener('message', function (event) {
            console.log("Received message from xiumi, origin: %o %o", event.origin, xiumi_url);
            if (event.origin == xiumi_url) {
                console.log("Inserting html");
                editor.execCommand('insertHtml', event.data);
                console.log("Xiumi dialog is closing");
                dialog.close();
            }
        }, false);
    </script>
</body>

</html>

將注冊(cè)的圖標(biāo)添加到編輯器中
react hook使用UEditor引入秀米圖文排版,業(yè)務(wù),筆記,react,react.js,前端,前端框架文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-836197.html

到了這里,關(guān)于react hook使用UEditor引入秀米圖文排版的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 前端開(kāi)發(fā)筆記 | React Hooks子組件和父組件交互

    前端開(kāi)發(fā)框架目前比較常用的就是react、vue等,其中使用React Hooks 帶來(lái)了不少的好處,今天來(lái)聊聊React Hooks開(kāi)發(fā)方式下,子組件和父組件的交互。 子組件定義 父組件調(diào)用子組件 父組件定義 子組件中刷新父組件按鈕文案 實(shí)際效果:點(diǎn)擊子組件中“改變父組件按鈕”,父組件中

    2024年02月11日
    瀏覽(15)
  • React Hooks 基本使用

    class 組件如果業(yè)務(wù)復(fù)雜,很難拆分和重構(gòu),很難測(cè)試;相同業(yè)務(wù)邏輯分散到各個(gè)方法中,邏輯混亂 邏輯復(fù)用像 HOC 、 Render Props ,不易理解,學(xué)習(xí)成本高 React 提倡函數(shù)式編程,函數(shù)更易拆分,更易測(cè)試 但是函數(shù)組件太簡(jiǎn)單,為了增強(qiáng)函數(shù)組件的功能,媲美 class 組件: 函數(shù)組

    2024年01月21日
    瀏覽(59)
  • 【《React Hooks實(shí)戰(zhàn)》——指導(dǎo)你使用hook開(kāi)發(fā)性能優(yōu)秀可復(fù)用性高的React組件】

    【《React Hooks實(shí)戰(zhàn)》——指導(dǎo)你使用hook開(kāi)發(fā)性能優(yōu)秀可復(fù)用性高的React組件】

    使用React Hooks后,你很快就會(huì)發(fā)現(xiàn),代碼變得更具有組織性且更易于維護(hù)。React Hooks是旨在為用戶提供跨組件的重用功能和共享功能的JavaScript函數(shù)。利用React Hooks, 可以將組件分成多個(gè)函數(shù)、管理狀態(tài)和副作用,并且不必聲明類(lèi)即可調(diào)用React內(nèi)置的功能。而且,上述所有的操作

    2024年02月14日
    瀏覽(24)
  • React Hooks 詳細(xì)使用介紹

    useState 是 React 中的一個(gè)基礎(chǔ) Hook,允許你在不使用 class 組件的情況下管理組件狀態(tài)。 參數(shù) 初始值 你可以直接傳遞狀態(tài)的初始值給 useState : 使用函數(shù)設(shè)置初始值 當(dāng)初始化狀態(tài)代價(jià)較大時(shí),你可以傳遞一個(gè)函數(shù): 返回值 useState 返回一個(gè)數(shù)組,其中包括當(dāng)前狀態(tài)值和一個(gè)更新

    2024年02月13日
    瀏覽(20)
  • react中hooks的理解與使用

    react中hooks的理解與使用

    一、作用 我們知道react組件有兩種寫(xiě)法一種是類(lèi)組件,另一種是函數(shù)組件。而函數(shù)組件是無(wú)狀態(tài)組件,如果我們要想改變組件中的狀態(tài)就無(wú)法實(shí)現(xiàn)了。為此,在react16.8版本后官方推出hooks,用于函數(shù)組件更改狀態(tài)。 二、常用API 1、useState :存儲(chǔ)變量和修改變量 用法: 有兩個(gè)參

    2024年02月13日
    瀏覽(24)
  • React - Redux Hooks的使用細(xì)節(jié)詳解

    Redux中Hooks介紹 在之前的redux開(kāi)發(fā)中,為了讓組件和redux結(jié)合起來(lái),我們使用了react-redux庫(kù)中的connect : 但是這種方式必須使用高階函數(shù)結(jié)合返回的高階組件; 并且必須編寫(xiě):mapStateToProps和 mapDispatchToProps映射的函數(shù), 具體使用方式在前面文章有講解; 在Redux7.1開(kāi)始,提供了Hook的方式

    2024年02月02日
    瀏覽(15)
  • react使用hook封裝一個(gè)tab組件
  • React Hooks的useState、useRef使用

    React Hooks 是 React 16.8 版本引入的新特性,它允許你在不編寫(xiě) class 的情況下使用 state 和其他 React 特性。其中, useState ?和? useRef ?是兩個(gè)常用的 Hooks。 1. useState useState ?是一個(gè)允許你在函數(shù)組件中添加 state 的 Hook。 使用說(shuō)明: useState ?返回一個(gè)狀態(tài)變量和一個(gè)設(shè)置該變量的函

    2024年02月02日
    瀏覽(22)
  • React的10個(gè)常用Hooks及使用場(chǎng)景

    React是一款非常流行的JavaScript庫(kù),它提供了許多Hooks,用于管理函數(shù)組件的狀態(tài)和生命周期。下面是React的每個(gè)Hooks的使用場(chǎng)景和示例: useState用于在函數(shù)組件中管理狀態(tài)。 它返回一個(gè)包含當(dāng)前狀態(tài)和一個(gè)更新?tīng)顟B(tài)的函數(shù)的數(shù)組。更新?tīng)顟B(tài)的函數(shù)可以接受一個(gè)新的值,并更新?tīng)?/p>

    2024年02月09日
    瀏覽(21)
  • React Hook - useEffecfa函數(shù)的使用細(xì)節(jié)詳解

    useEffecf基本使用 書(shū)接上文, 上一篇文章我們講解了State Hook, 我們已經(jīng)可以通過(guò)這個(gè)hook在函數(shù)式組件中定義state 我們知道在類(lèi)組件中是可以有生命周期函數(shù)的, 那么如何在函數(shù)組件中定義類(lèi)似于生命周期這些函數(shù)呢? Effect Hook 可以讓你來(lái)完成一些類(lèi)似于class中生命周期的功能; 事

    2023年04月12日
    瀏覽(20)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包