小程序富文本图片预览

原生平台

  • npm 方式

    1. 在项目目录下安装组件包

      npm install mp-html
    2. 开发者工具中勾选 使用 npm 模块(若没有此选项则不需要)并点击 工具 - 构建 npm

    3. 在需要使用页面的 json 文件中添加

      {
        "usingComponents": {
          "mp-html": "mp-html"
        }
      }
    4. 在需要使用页面的 wxml 文件中添加

      <mp-html content="{{html}}" />
    5. 在需要使用页面的 js 文件中添加

      Page({
        onLoad () {
          this.setData({
            html: '<div>Hello World!</div>'
          })
        }
      })
  • 源码方式

    1. 将源码中对应平台的代码包(dist/platform)拷贝到 components 目录下,更名为 mp-html

    2. 在需要使用页面的 json 文件中添加

      {
        "usingComponents": {
          "mp-html": "/components/mp-html/index"
        }
      }

    后续步骤同上

查看 快速开始 了解更多

uni-app

  • 源码方式

    1. 将源码中 dist/uni-app 内的内容拷贝到项目根目录下
      可以直接通过 插件市场 引入

    2. 在需要使用页面的 vue 文件中添加

      <template>
        <view>
          <mp-html :content="html" />
        </view>
      </template>
      <script>
        import mpHtml from '@/components/mp-html/mp-html'
        export default {
          // HBuilderX 2.5.5+ 可以通过 easycom 自动引入
          components: {
            mpHtml
          },
          data () {
            return {
              html: '<div>Hello World!</div>'
            }
          }
        }
      </script>
  • npm 方式

    1. 在项目目录下安装组件包

      npm install mp-html
    2. 在需要使用页面的 vue 文件中添加

      <template>
        <view>
          <mp-html :content="html" />
        </view>
      </template>
      <script>
        import mpHtml from 'mp-html/dist/uni-app/components/mp-html/mp-html'
        export default {
          // 不可省略
          components: {
            mpHtml
          },
          data () {
            return {
              html: '<div>Hello World!</div>'
            }
          }
        }
      </script>

    使用 cli 方式运行的项目,通过 npm 方式引入时,需要在 vue.config.js 中配置 transpileDependencies,详情可见 #330
    如果在 nvue 中使用还要将 dist/uni-app/static 目录下的内容拷贝到项目的 static 目录下,否则无法运行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值