美文网首页
前端小庙之 React-Native 里html标签转换(rea

前端小庙之 React-Native 里html标签转换(rea

作者: 菠菜_yaya | 来源:发表于2018-11-22 14:08 被阅读0次

【师傅,你知道我在想谁么?】
【昨天那个女施主。】
【你怎么知道。】
【我也在想。】
【那你怎么睡得着?】
【那是大方丈的闺女,想也白想。】
【师傅,那Vue怎么绑定HTML嘛】
【v-html,简单】
【哦,那react呢】
【用dangerouslySetInnerHTML,无趣】
【哦,那React-native呢】
【这。。。时间不早了,早点睡吧】

react-native-htmlview

使用react-native-htmlview将html 代码片段渲染为RN组件,还可以定制你喜欢的样式

import React from 'react';
import {StyleSheet} from 'react-native';
import HTMLView from 'react-native-htmlview';

class App extends React.Component {
  render() {
    const htmlContent = `<p><a href="http://jsdf.co">&hearts; nice job!</a></p>`;

    return (
      <HTMLView
        value={htmlContent}
        stylesheet={styles}
      />
    );
  }
}

const styles = StyleSheet.create({
  a: {
    fontWeight: '300',
    color: '#FF3366', // make links coloured pink
  },
});

github地址:react-native-htmlview

相关文章

网友评论

      本文标题:前端小庙之 React-Native 里html标签转换(rea

      本文链接:https://www.haomeiwen.com/subject/etrlqqtx.html