我正在通过他们的无头api从wordpress获取内容。但是返回的文本显示的是html标签,我只想要没有html的纯文本。然后我如何添加分隔符,并使文本的某些部分加粗等等。
这是我压缩的代码;
componentDidMount(){
const pageURL = "http://localhost:8888/wp-json/wp/v2/pages/5";
fetch(pageURL)
.then(response => response.json())
.then(response => {
this.setState({
content: response.content.rendered
});
})
}
render() {
let content = this.state.content;
return (
<div className="AboutUsContainer">
<div className="Bio">
<p>{content}</p>
</div>
</div>
)
}
}有什么帮助吗?
发布于 2020-10-18 21:15:36
我认为这会对你有帮助,就像@ali所说的,
用这行而不是你的
this.setState({
content: response.content.rendered.replace(/<\/?([a-z][a-z0-9]*)\b[^>]*>/gi, '');
});发布于 2019-03-11 19:29:47
使用str.replace(/<\/?[^>]+>/gi, '')显示内容。这么简单。
https://stackoverflow.com/questions/51620643
复制相似问题