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

微信小程序editor富文本編輯器

這篇具有很好參考價(jià)值的文章主要介紹了微信小程序editor富文本編輯器。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

????????在開(kāi)發(fā)小程序的時(shí)候,需要用到發(fā)布文章這個(gè)功能,于是就需要使用富文本編輯器。而微信小程序則正好有editor這個(gè)組件,不過(guò)editor組件的功能,還需要我們自己去調(diào)用富文本編輯器的api去自定義。富文本在wxml中可使用<rich-text nodes="{{ value }}"></<rich-text>標(biāo)簽展示。想直接用的可以跳到二、(4)。如果你也向我一樣從0開(kāi)始搭建,那真的是鈦褲辣!

一、準(zhǔn)備工作

先看看效果圖,然后我們?cè)龠M(jìn)一步進(jìn)行搭建。

微信小程序editor富文本編輯器

?????????我們先看官方文檔,搭建上面的這種編輯器需要用到bindready(初始化實(shí)例編輯器)、bindfocus(光標(biāo)聚焦)、bindblur(光標(biāo)失焦)、bindinput(輸入內(nèi)容時(shí)觸發(fā))、bindstatuschange(工具欄狀態(tài)發(fā)生變化時(shí)觸發(fā))這幾個(gè)屬性。

微信小程序editor富文本編輯器

點(diǎn)擊相關(guān) api:EditorContext可以看到這樣一些方法,在調(diào)用這些方法之前需要?jiǎng)?chuàng)建一個(gè)實(shí)例,只有通過(guò)這個(gè)實(shí)例才能夠調(diào)用以下的這些方法。創(chuàng)建實(shí)例需要用到?wx.createSelectorQuery?,相關(guān)創(chuàng)建的代碼放到下文。創(chuàng)建完實(shí)例后,我們將會(huì)用到以下幾個(gè)方法:

1、EditorContext.format(string name, string value)(修改樣式,name和value需要在wxml進(jìn)行綁定)

2、EditorContext.insertDivider()(插入分割線(xiàn),需要綁定事件)

3、EditorContext.insertImage(Object object)(插入圖片,需要綁定事件)

4、EditorContext.blur()(鍵盤(pán)失焦時(shí)收起鍵盤(pán))

EditorContexthttps://developers.weixin.qq.com/miniprogram/dev/api/media/editor/EditorContext.html

?微信小程序editor富文本編輯器

?二、開(kāi)始創(chuàng)建

1、wxml如下代碼

????????在editor中綁定bindready(初始化實(shí)例編輯器)、bindfocus(光標(biāo)聚焦)、bindblur(光標(biāo)失焦)、bindinput(輸入內(nèi)容時(shí)觸發(fā))、bindstatuschange(工具欄狀態(tài)發(fā)生變化時(shí)觸發(fā))這幾個(gè)屬性。在toolBar中綁定catchtouchend(點(diǎn)擊工具欄時(shí)獲取狀態(tài))。我們現(xiàn)在只需要管這幾個(gè)事件、其他的class和style樣式可以忽略。

<!--pages/oneEditor/oneEditor.wxml-->
  <view>
    <editor id="editor"  bindready="onEditorReady" bindinput="onInput" bindblur="onBlur" bindstatuschange="onStatusChange">
    </editor>
  </view>
  <view class="toolBar" catchtouchend="format">
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
    <i></i>
  </view>

2、JS代碼如下,我們按照函數(shù)調(diào)用的順序進(jìn)行講解

(1)在初始化編輯器時(shí)需要用到<editor>中的id="editor"? bindready="onEditorReady",這里用到的上面講的wx.createSelectorQuery()。oneEditor就是我們生成的實(shí)例,隨便你取啥名,到時(shí)候調(diào)用方法的時(shí)候使用,例如this.oneEditor.format()。

 onEditorReady(){
    var that=this
    // 初始化一個(gè)實(shí)例
    wx.createSelectorQuery().select('#editor').context(res=>{
      that.oneEditor=res.context
      console.log(res.context)
    }).exec()
  },

(2) 初始化完成后(因?yàn)閏lass和style還沒(méi)有添加,所以你們顯示的效果圖和我的不一樣),可以用到<editor>中的οninput="onInput"了,輸入1111111可以看到輸出的html。

onInput(e){
    console.log(e.detail.delta.ops)
    console.log("html",e.detail.html)
  },

微信小程序editor富文本編輯器

(3)<editor>中的?bindblur="onBlur" ,這里就用到上面的實(shí)例了,調(diào)用這個(gè)方法可以在失焦的時(shí)候收起鍵盤(pán)。

  onBlur(e){
    console.log(e)
    this.oneEditor.blur()
  },

?(4)<editor>中的bindstatuschange="onStatusChange"就需要我們?cè)诓渴鹜阠lass后講解了,因?yàn)檫@里涉及到工具欄狀態(tài)的變化,而我們工具欄還沒(méi)有部署。下面開(kāi)始部署工具欄的樣式,回到組件那個(gè)頁(yè)面,因?yàn)槲覀冃枰玫焦俜降臉邮胶蛨D標(biāo),所以得去官網(wǎng)找樣式代碼。

微信小程序editor富文本編輯器

?微信小程序editor富文本編輯器微信小程序editor富文本編輯器

(5)?這個(gè)代碼片段其實(shí)就是一個(gè)編輯器了,但是我們從0開(kāi)始搭建真的是鈦褲辣!(體驗(yàn)的就是一個(gè)過(guò)程的樂(lè)趣)。然后我們把common移到我們自己的項(xiàng)目中去,需要和你的編輯器同層級(jí)(方便應(yīng)用),把a(bǔ)ssets移到你的編輯器里面,就行了。

?微信小程序editor富文本編輯器微信小程序editor富文本編輯器

?然后我們的class就可以全部加上啦(再加上上面的wxml怕你們忘了)wxml代碼如下:

<!--pages/oneEditor/oneEditor.wxml-->
  <view class="editor_container" style="height:{{editorHeight}}rpx">
    <editor id="editor" class="editor" placeholder="{{placeholder}}"    bindready="onEditorReady" bindinput="onInput" bindblur="onBlur" bindstatuschange="onStatusChange">
    </editor>
  </view>
  <view class="toolBar" catchtouchend="format" style="bottom:{{keyboardHeight}}px">
    <i class="iconfont icon-charutupian" catchtouchend="insertImage"></i>
    <i class="iconfont icon-fengexian" catchtouchend="addDivider"></i>
    <i class="iconfont icon-format-header-1 {{formats.header===1?'active':''}}" data-name="header" data-value="1"></i>
    <i class="iconfont icon-format-header-2 {{formats.header===2?'active':''}}" data-name="header" data-value="2"></i>
    <i class="iconfont icon-format-header-3 {{formats.header===3?'active':''}}" data-name="header" data-value="3"></i>
    <i class="iconfont icon-format-header-4 {{formats.header===4?'active':''}}" data-name="header" data-value="4"></i>
    <i class="iconfont icon-zitixiahuaxian {{formats.underline?'active':''}}" data-name="underline"></i>
    <i class="iconfont icon-zitijiacu {{formats.bold?'active':''}}" data-name="bold"></i>
    <i class="iconfont icon-zitixieti {{formats.italic=='em'?'active':''}}" data-name="italic"></i>
    <i class="iconfont icon-zuoduiqi {{formats.align=='left'?'active':''}}" data-name="align" data-value="left"></i>
    <i class="iconfont icon-juzhongduiqi {{formats.align=='center'?'active':''}}" data-name="align"
      data-value="center"></i>
    <i class="iconfont icon-youduiqi {{formats.align=='right'?'active':''}}" data-name="align" data-value="right"></i>
    <i class="iconfont icon-zuoyouduiqi {{formats.align=='justify'?'active':''}}" data-name="align"
      data-value="justify"></i>
    <i class="iconfont icon-zitishanchuxian {{formats.strike=='del'?'active':''}}" data-name="strike"></i>
    <i class="iconfont icon-clearedformat" catchtouchend="clearFormat"></i>
  </view>

(6)wxss代碼入下,引入官方的樣式和圖標(biāo),具體的圖標(biāo)樣式還需要自己在asserts中的iconfont去尋找引用格式為class="iconfont icon+具體樣式",樣式有了。那么上面的{{formats}}、data-name、datavalue是咋回事捏。下面開(kāi)始講。

/* pages/oneEditor/oneEditor.wxss */
@import "../common/lib/weui.wxss";
@import "./assets/iconfont.wxss";
.tool{
  margin-left: 10rpx;
}
.iconfont {
  display: inline-block;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 20px;
}
.editor_container {
  /* position: absolute;  */
  top: 0; 
  left: 0; 
  width: 100%;
}
.editor {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  font-size: 16px;
  line-height: 1.5;
  overflow: auto;
  padding: 10px 10px 20px 10px;
  border: 1px solid #ECECEC;
}
.active{
  color: #409EFF;
}
.toolBar{
  box-sizing: border-box;
  padding: 0 10px;
  height: 50px;
  width: 100%;
  position: fixed;
  left: 0;
  right: 100%;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #ECECEC;
  border-left: none;
  border-right: none;
}

(7)怕看岔了,于是把上面wxml再粘貼下來(lái)了,這里講bindstatuschange="onStatusChange"和catchtouchend="format"這倆是一塊的。

<!--pages/oneEditor/oneEditor.wxml-->
  <view class="editor_container" style="height:{{editorHeight}}rpx">
    <editor id="editor" class="editor" placeholder="{{placeholder}}"    bindready="onEditorReady" bindinput="onInput" bindblur="onBlur" bindstatuschange="onStatusChange">
    </editor>
  </view>
  <view class="toolBar" catchtouchend="format" style="bottom:{{keyboardHeight}}px">
    <i class="iconfont icon-charutupian" catchtouchend="insertImage"></i>
    <i class="iconfont icon-fengexian" catchtouchend="addDivider"></i>
    <i class="iconfont icon-format-header-1 {{formats.header===1?'active':''}}" data-name="header" data-value="1"></i>
    <i class="iconfont icon-format-header-2 {{formats.header===2?'active':''}}" data-name="header" data-value="2"></i>
    <i class="iconfont icon-format-header-3 {{formats.header===3?'active':''}}" data-name="header" data-value="3"></i>
    <i class="iconfont icon-format-header-4 {{formats.header===4?'active':''}}" data-name="header" data-value="4"></i>
    <i class="iconfont icon-zitixiahuaxian {{formats.underline?'active':''}}" data-name="underline"></i>
    <i class="iconfont icon-zitijiacu {{formats.bold?'active':''}}" data-name="bold"></i>
    <i class="iconfont icon-zitixieti {{formats.italic=='em'?'active':''}}" data-name="italic"></i>
    <i class="iconfont icon-zuoduiqi {{formats.align=='left'?'active':''}}" data-name="align" data-value="left"></i>
    <i class="iconfont icon-juzhongduiqi {{formats.align=='center'?'active':''}}" data-name="align"
      data-value="center"></i>
    <i class="iconfont icon-youduiqi {{formats.align=='right'?'active':''}}" data-name="align" data-value="right"></i>
    <i class="iconfont icon-zuoyouduiqi {{formats.align=='justify'?'active':''}}" data-name="align"
      data-value="justify"></i>
    <i class="iconfont icon-zitishanchuxian {{formats.strike=='del'?'active':''}}" data-name="strike"></i>
    <i class="iconfont icon-clearedformat" catchtouchend="clearFormat"></i>
  </view>

(8)onStatusChange,先在<i>中綁定data-name,name的名字參考官方文檔,我點(diǎn)擊了斜體(看52行),然后這個(gè)函數(shù)就把工具欄的開(kāi)啟狀態(tài)記錄下來(lái)了,于是我們只需根據(jù)formats的值來(lái)判斷是否開(kāi)啟了工具欄的某個(gè)功能,改變class中的觸發(fā)樣式,比如我把a(bǔ)ctive設(shè)置成了藍(lán)色。

微信小程序editor富文本編輯器

(9)?format是用來(lái)保存當(dāng)前樣式的,比如我點(diǎn)擊H1,會(huì)記錄一個(gè)name:header標(biāo)識(shí)這個(gè)是標(biāo)題,而value:1標(biāo)識(shí)這是一個(gè)一級(jí)標(biāo)題,其他的類(lèi)似。

微信小程序editor富文本編輯器

?3、通過(guò)實(shí)例調(diào)用api

只需要在wxml綁定函數(shù),并在函數(shù)里面調(diào)用api就可以了,例如插入下劃線(xiàn),我在wxml用catchtouchend="addDivider"綁定了一個(gè)事件

  addDivider(){
    this.oneEditor.insertDivider(res=>{
      console.log(res)
    })
  },

微信小程序editor富文本編輯器

?還有一些調(diào)整鍵盤(pán)高度和上傳圖片這里就不講了吧,直接上代碼。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-488088.html

 onLoad: function (options) {
    //獲取鍵盤(pán)高度
    wx.onKeyboardHeightChange((res) => {          
      console.log("KeyboardHeight",res.height)
      this.oneEditor.scrollIntoView()
      this.setData({
        keyboradHight:res.height
      })
    })
  },
insertImage(){
    var that=this
    wx.chooseMedia({
      count:1,
      mediaType:['image'],
      sourceType:['album', 'camera'],
      success(res){
        console.log(res)
        let url=res.tempFiles[0].tempFilePath
          that.oneEditor.insertImage({
            src:url,
            extClass:"image",
            alt:"圖片加載錯(cuò)誤",
            width:"100%",
            height:"300rpx"
          })
      }
    })
   
  },

到了這里,關(guān)于微信小程序editor富文本編輯器的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶(hù)投稿,該文觀(guān)點(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)文章

  • 小程序Editor富文本編輯器-封裝使用用法

    小程序Editor富文本編輯器-封裝使用用法

    本文章主要講述editor中小程序的圖片上傳和pc端數(shù)據(jù)不同步的問(wèn)題,建議多看下代碼 完整代碼在最下面 1、創(chuàng)建個(gè)用于組件封裝的editor文件夾,存放三個(gè)文件 ?2、editor.vue文件是主要封裝代碼 3、editor-icon.css文件樣式 5、如果上傳圖片失敗或者是圖片裂開(kāi),和pc端數(shù)據(jù)不同步的話(huà)

    2024年02月11日
    瀏覽(24)
  • Eclipse - Text Editors (文本編輯器)

    Eclipse - Text Editors (文本編輯器)

    Window - Preferences - General - Editors - Text Editors Displayed tab witdth: 4 勾選 Insert spaces for tabs 勾選 Show line number [1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

    2024年02月21日
    瀏覽(24)
  • 富文本編輯器 ck-editor5 的使用

    富文本編輯器 ck-editor5 的使用

    最近在項(xiàng)目中需要用到富文本編輯器,據(jù)說(shuō)ck-editor5很不錯(cuò),于是就使用它了,不過(guò)在期間也遇到了很多問(wèn)題,這里記錄下。 一、引入ck-editor5 文檔地址:Predefined builds - CKEditor 5 Documentation 這里有個(gè)坑,我最初是根據(jù)文檔執(zhí)行下面的npm命令下載的,最后搗騰了半天發(fā)現(xiàn)里面功能

    2024年01月20日
    瀏覽(16)
  • 富文本編輯器 VUE-QUILL-EDITOR 使用教程

    富文本編輯器 VUE-QUILL-EDITOR 使用教程

    1、NPM 導(dǎo)入 VUE-QUILL-EDITOR 2、引入 VUE-QUILL-EDITOR 在全局中引入 在指定的 vue 文件中引入 3、在 VUE 中使用 到這里一個(gè)默認(rèn)的富文本編輯器已經(jīng)導(dǎo)入使用了,如下圖所視! 一般的,我們?cè)谑褂玫臅r(shí)候并不需要這么多功能,可以適當(dāng)?shù)膶?duì)編輯器配置項(xiàng)進(jìn)行配置。 可以根據(jù)自己的實(shí)際

    2024年02月09日
    瀏覽(29)
  • vue-quill-editor富文本編輯器使用步驟

    vue-quill-editor富文本編輯器使用步驟

    首先放上效果圖 目錄 1.安裝 2.引入到項(xiàng)目中 3.在頁(yè)面上寫(xiě)組件 4.配置option 5.給工具欄鼠標(biāo)懸停加上中文釋義 6.上傳圖片到七牛云 7.自定義控制圖片大小 1.安裝 2.引入到項(xiàng)目中 ????????有兩種掛載方式: 全局掛載 和 在組件中掛載,根據(jù)自己的項(xiàng)目需求選擇,一般用到富文

    2024年02月06日
    瀏覽(28)
  • 富文本編輯器 VUE-QUILL-EDITOR 使用教程 (最全)

    富文本編輯器 VUE-QUILL-EDITOR 使用教程 (最全)

    VUE-QUILL-EDITOR 基于 QUILL、適用于 VUE 的富文本編輯器,支持服務(wù)端渲染和單頁(yè)應(yīng)用,非常高效簡(jiǎn)潔。 在全局中引入 在指定的 vue 文件中引入 到這里一個(gè)默認(rèn)的富文本編輯器已經(jīng)導(dǎo)入使用了,如下圖所視! 一般的,我們?cè)谑褂玫臅r(shí)候并不需要這么多功能,可以適當(dāng)?shù)膶?duì)編輯器配

    2024年02月04日
    瀏覽(20)
  • vue使用富文本編輯器vue-quill-editor

    vue使用富文本編輯器vue-quill-editor

    問(wèn)題描述: 我們?cè)陂_(kāi)發(fā)過(guò)程中經(jīng)常會(huì)遇到使用富文本編輯器進(jìn)行操作,當(dāng)前插件市場(chǎng)上關(guān)于富文本的編輯器挺多的,我們就不一一個(gè)介紹了,現(xiàn)在我們主要講解一些vue-quill-editor富文本編輯器的使用操作和注意事項(xiàng)。 效果圖 具體操作使用 1. 安裝 2. 引入到項(xiàng)目中 有兩種掛載方

    2024年02月02日
    瀏覽(33)
  • 簡(jiǎn)版的富文本編輯器、VUE+ElementUI 富文本編輯器 element ui富文本編輯器的使用(quill-editor) 不好用你來(lái)打我!全網(wǎng)醉簡(jiǎn)單!要復(fù)雜的別來(lái)!

    簡(jiǎn)版的富文本編輯器、VUE+ElementUI 富文本編輯器 element ui富文本編輯器的使用(quill-editor) 不好用你來(lái)打我!全網(wǎng)醉簡(jiǎn)單!要復(fù)雜的別來(lái)!

    實(shí)現(xiàn)效果 ? 1.安裝插件 npm install vue-quill-editor --save 2.安裝成功后在package.json中查看 3.在main.js中全局引入插件 4.頁(yè)面實(shí)現(xiàn) 感謝老哥:?ElementUI生成富文本編輯器 https://blog.csdn.net/keplerm/article/details/123379511?spm=1001.2101.3001.6650.9utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCom

    2024年02月16日
    瀏覽(29)
  • element ui富文本編輯器的使用(quill-editor)

    element ui富文本編輯器的使用(quill-editor)

    可以拖拽圖片大小及其位置 為了便于大家直接使用,直接把script以及css放在一個(gè)頁(yè)面里,之際copy就可以使用 注意: 1、我是在elementUi使用的,上傳圖片以及頁(yè)面的訪(fǎng)問(wèn)需要有登錄權(quán)限,所以我的上傳圖片視頻的組件里有:headers=“headers”,攜帶登錄權(quán)限 2、需要更改自己的上

    2024年02月03日
    瀏覽(20)
  • vue-quill-editor富文本編輯器-擴(kuò)展表格、圖片調(diào)整大小

    vue-quill-editor富文本編輯器-擴(kuò)展表格、圖片調(diào)整大小

    上篇文章已經(jīng)講到、vue-quill-editor的基本配置和圖片轉(zhuǎn)成url 這篇文章主要使用插件來(lái)完成 圖片調(diào)整大小 和 表格的插件使用( 這兩個(gè)目前quill 版本并不兼容 如果有大神解決了還望指點(diǎn) ) 參考文章: vue-quill-editor 富文本編輯器支持圖片拖拽和放大縮小_*且聽(tīng)風(fēng)吟的博客-CSDN博

    2024年02月04日
    瀏覽(93)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包