最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue2使用wangeditor實(shí)現(xiàn)手寫輸入功能

 更新時(shí)間:2023年12月12日 10:05:41   作者:請(qǐng)叫我歐皇i  
這篇文章主要為大家詳細(xì)介紹了vue2如何使用wangeditor實(shí)現(xiàn)手寫輸入功能,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以了解下

1.效果

2.實(shí)現(xiàn)

2.1:先看我上一篇,這篇就是在上一篇的基礎(chǔ)上添加一個(gè)手寫功能,導(dǎo)入注冊(cè)就行了

vue2使用wangeditor實(shí)現(xiàn)數(shù)學(xué)公式+富文本編輯器

在components中添加myscriptMath.js 

svg也就是個(gè)顯示的圖標(biāo),可以替換為其他

import $ from "jquery";
import { mathIcon } from "../assets/icons/svg-icon.ts";
 
class MyScriptMathMenu {
  constructor() {
    this.title = "手寫公式";
    this.iconSvg = mathIcon;
    this.tag = "button";
    this.showModal = true;
    this.modalWidth = 900;
    this.modalHeight = 500;
  }
 
  // 菜單是否需要激活(如選中加粗文本,“加粗”菜單會(huì)激活),用不到則返回 false
  isActive(editor) {
    return false;
  }
 
  // 獲取菜單執(zhí)行時(shí)的 value ,用不到則返回空 字符串或 false
  getValue(editor) {
    return "";
  }
 
  // 菜單是否需要禁用(如選中 H1 ,“引用”菜單被禁用),用不到則返回 false
  isDisabled(editor) {
    return false;
  }
  // 點(diǎn)擊菜單時(shí)觸發(fā)的函數(shù)
  exec(editor, value) {
    // Modal menu ,這個(gè)函數(shù)不用寫,空著即可
  }
 
  // 彈出框 modal 的定位:1. 返回某一個(gè) SlateNode; 2. 返回 null (根據(jù)當(dāng)前選區(qū)自動(dòng)定位)
  getModalPositionNode(editor) {
    return null; // modal 依據(jù)選區(qū)定位
  }
 
  // 定義 modal 內(nèi)部的 DOM Element
  getModalContentElem(editor) {
    // panel 中需要用到的id
    const inputIFrameId = "kityformula_" + Math.ceil(Math.random() * 10);
    const btnOkId = "kityformula-btn" + Math.ceil(Math.random() * 10);
 
    const $content = $(`
    <div>
      <iframe id="${inputIFrameId}" class="iframe" height="400px" width="100%" frameborder="0" scrolling="no" src="/myscriptMath/index.html"></iframe>
    </div>`);
    const $button = $(
      `<button id="${btnOkId}" class="right" style='margin: 5px 0'>
        確認(rèn)插入
      </button>`
    );
    $content.append($button);
 
    $button.on("click", () => {
      // 執(zhí)行插入公式
      const node = document.getElementById(inputIFrameId);
      const latex = node.contentWindow.latex;
 
      const formulaNode = {
        type: "paragraph",
        children: [
          {
            type: "formula",
            value: latex,
            children: [
              {
                text: "",
              },
            ],
          },
        ],
      };
      editor.insertNode(formulaNode);
      editor.hidePanelOrModal();
    });
 
    return $content[0]; // 返回 DOM Element 類型
 
    // PS:也可以把 $content 緩存下來,這樣不用每次重復(fù)創(chuàng)建、重復(fù)綁定事件,優(yōu)化性能
  }
}
const menuConf = {
  key: "myscriptMath", // menu key ,唯一。注冊(cè)之后,需通過 toolbarKeys 配置到工具欄
  factory() {
    return new MyScriptMathMenu();
  },
};
 
export default menuConf;

2.2導(dǎo)入注冊(cè)實(shí)現(xiàn)

import myscriptMath from "@/components/myscriptMath";
import { Boot } from "@wangeditor/editor";
      toolbarConfig: {
        // 插入編輯公式菜單
        insertKeys: {
          index: 0,
          keys: [
            "kityFormula", // “編輯公式”菜單
            "myscriptMath",
          ],
        },
        // excludeKeys: [ /* 隱藏哪些菜單 */ ],
      },
  created() {
    Boot.registerMenu(myscriptMath);
  },

3.完整代碼

<template>
  <div class="content-box">
    <div class="container" style="width: 1000px; margin: 0 auto">
      <div>
        <button @click="printEditorHtml">獲取編輯器html</button>
        <button @click="getEditorText">獲取編輯器文本</button>
      </div>
      <div style="border: 1px solid #ccc; margin-top: 10px; text-align: left">
        <!-- 工具欄 -->
        <Toolbar
          style="border-bottom: 1px solid #ccc"
          :editor="editor"
          :defaultConfig="toolbarConfig"
        />
        <!-- 編輯器 -->
        <Editor
          style="height: 500px; overflow-y: hidden"
          :defaultConfig="editorConfig"
          v-model="html"
          @onChange="onChange"
          @onCreated="onCreated"
          @onFocus="handleFocus"
        />
      </div>
      <div style="margin-top: 10px">
        <textarea
          v-model="html"
          readonly
          style="width: 100%; height: 200px; outline: none"
        ></textarea>
      </div>
    </div>
  </div>
</template>
 
<script>
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
import kityformula from "@/components/kityformula";
import myscriptMath from "@/components/myscriptMath";
import { Boot } from "@wangeditor/editor";
import formulaModule from "@wangeditor/plugin-formula";
export default {
  name: "MyEditor",
  components: { Editor, Toolbar },
  data() {
    return {
      editor: null,
      html: "<p>hello&nbsp;world</p>",
      toolbarConfig: {
        // 插入編輯公式菜單
        insertKeys: {
          index: 0,
          keys: [
            "kityFormula", // “編輯公式”菜單
            "myscriptMath",
          ],
        },
        // excludeKeys: [ /* 隱藏哪些菜單 */ ],
      },
      editorConfig: {
        placeholder: "請(qǐng)輸入內(nèi)容...",
        // autoFocus: false,
 
        // 所有的菜單配置,都要在 MENU_CONF 屬性下
        MENU_CONF: {},
      },
    };
  },
  methods: {
    onCreated(editor) {
      console.log("created", editor);
      this.editor = Object.seal(editor); // 【注意】一定要用 Object.seal() 否則會(huì)報(bào)錯(cuò)
    },
    onChange(editor) {
      console.log("onChange", editor.getHtml()); // onChange 時(shí)獲取編輯器最新內(nèi)容
    },
    handleFocus(editor) {
      console.log("focus", editor);
    },
    getEditorText() {
      const editor = this.editor;
      if (editor == null) return;
 
      console.log(editor.getText()); // 執(zhí)行 editor API
    },
    printEditorHtml() {
      const editor = this.editor;
      if (editor == null) return;
 
      console.log(editor.getHtml()); // 執(zhí)行 editor API
    },
  },
  created() {
    Boot.registerMenu(kityformula);
    Boot.registerMenu(myscriptMath);
    Boot.registerModule(formulaModule);
  },
  mounted() {
    // 模擬 ajax 請(qǐng)求,異步渲染編輯器
    setTimeout(() => {
      this.html = "<p>Ajax 異步設(shè)置內(nèi)容 HTML</p>";
    }, 1500);
  },
  beforeDestroy() {
    const editor = this.editor;
    if (editor == null) return;
    editor.destroy(); // 組件銷毀時(shí),及時(shí)銷毀 editor ,重要!??!
  },
};
</script>
 
<style src="@wangeditor/editor/dist/css/style.css"></style>

到此這篇關(guān)于vue2使用wangeditor實(shí)現(xiàn)手寫輸入功能的文章就介紹到這了,更多相關(guān)vue2 wangeditor手寫輸入內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue.js中兄弟組件之間互相傳值實(shí)例

    Vue.js中兄弟組件之間互相傳值實(shí)例

    本篇文章主要介紹了Vue.js中兄弟組件之間互相傳值實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-06-06
  • 深入探究Vue中$nextTick的實(shí)現(xiàn)原理

    深入探究Vue中$nextTick的實(shí)現(xiàn)原理

    這篇文章主要為大家詳細(xì)介紹Vue中$nextTick的實(shí)現(xiàn)原理,文中的示例代碼講解詳細(xì),對(duì)我們深入了解Vue有一定的幫助,需要的小伙伴可以參考一下
    2023-06-06
  • vue+uniapp瀑布流布局多種實(shí)現(xiàn)方式示例代碼

    vue+uniapp瀑布流布局多種實(shí)現(xiàn)方式示例代碼

    由于使用uniapp開發(fā)的微信小程序不需要考慮響應(yīng)式,因此瀑布流的實(shí)現(xiàn)相對(duì)于pc端更為簡單,下面這篇文章主要給大家介紹了關(guān)于vue+uniapp瀑布流布局多種實(shí)現(xiàn)方式的相關(guān)資料,需要的朋友可以參考下
    2023-03-03
  • vue項(xiàng)目使用高德地圖時(shí)報(bào)錯(cuò):AMap?is?not?defined解決辦法

    vue項(xiàng)目使用高德地圖時(shí)報(bào)錯(cuò):AMap?is?not?defined解決辦法

    這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目使用高德地圖時(shí)報(bào)錯(cuò):AMap?is?not?defined的解決辦法,"AMap is not defined"是一個(gè)錯(cuò)誤提示,意思是在代碼中沒有找到定義的AMap,需要的朋友可以參考下
    2023-12-12
  • 如何使用vue過濾器filter

    如何使用vue過濾器filter

    這篇文章主要介紹了如何使用vue過濾器filter,對(duì)vue感興趣的同學(xué),可以參考下
    2021-05-05
  • 在vue中實(shí)現(xiàn)嵌套頁面(iframe)

    在vue中實(shí)現(xiàn)嵌套頁面(iframe)

    這篇文章主要介紹了在vue中實(shí)現(xiàn)嵌套頁面(iframe),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • Vue實(shí)現(xiàn)自動(dòng)檢測以及版本的更新

    Vue實(shí)現(xiàn)自動(dòng)檢測以及版本的更新

    當(dāng)用戶在當(dāng)前站點(diǎn)停留時(shí)間比較長,中途站點(diǎn)進(jìn)行升級(jí)更新之后,用戶如果不刷新頁面就任然停留在舊的頁面里,如何讓用戶收到一個(gè)提示,引導(dǎo)用戶進(jìn)行更新操作呢?下面給大家介紹如何站點(diǎn)更新如何在生產(chǎn)環(huán)境提示用戶更新,進(jìn)行頁面刷新操作,核心原理其實(shí)很簡單
    2023-03-03
  • axios攔截器工作方式及原理源碼解析

    axios攔截器工作方式及原理源碼解析

    這篇文章主要為大家介紹了axios攔截器工作原理源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • VUE+node(express)實(shí)現(xiàn)前后端分離

    VUE+node(express)實(shí)現(xiàn)前后端分離

    在本篇文章里小編給大家分享的是關(guān)于VUE+node(express)前后端分離實(shí)例內(nèi)容,有需要的朋友們參考下。
    2019-10-10
  • vue實(shí)現(xiàn)文件上傳

    vue實(shí)現(xiàn)文件上傳

    這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)文件上傳功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04

最新評(píng)論

元阳县| 拜泉县| 灌云县| 来宾市| 高平市| 乐业县| 门源| 石泉县| 崇州市| 阳春市| 孝义市| 房产| 彝良县| 景德镇市| 南康市| 宽城| 山东| 佛坪县| 莱阳市| 鄂温| 太和县| 达孜县| 海盐县| 秀山| 蓝田县| 集贤县| 惠东县| 灵石县| 社旗县| 开阳县| 阿克苏市| 周宁县| 承德县| 邓州市| 丰顺县| 肥东县| 灵山县| 亳州市| 宁化县| 赣州市| 泰安市|