小程序實現富文本編輯器,文本格式化


小程序實現html代碼

項目中用到富文本編輯器的內容,但微信小程序默認不支持 html代碼,在網上發現 wxParse能夠實現富文本編輯器
項目地址:

https://github.com/icindy/wxParse

下載后用到 wxParse 文件夾,直接拷貝至我們的項目下

1.在 js 中引入 wxParse.js
2.在 wxss 中引入  wxParse.js
3.通過調用WxParse.wxParse方法來設置html內容

/**
* WxParse.wxParse(bindName , type, data, target,imagePadding)
* 1.bindName綁定的數據名(必填)
* 2.type可以為html或者md(必填)
* 3.data為傳入的具體數據(必填)
* 4.target為Page對象,一般為this(必填)
* 5.imagePadding為當圖片自適應是左右的單一padding(默認為0,可選)
*/
4.在頁面中引用模版
<import src="../../wxParse/wxParse.wxml"/>
<template is="wxParse" data="{{wxParseData:article.nodes}}"/>

demo

Page({
  data: {
  },
  onLoad: function () {
    var that = this;
    var article = res.data[0].post;
     WxParse.wxParse('article', 'html', article, that,5);
        }
})

這樣就能簡單的是現在小程序中富文本編輯器的引用了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM