Render HTML to React Native
import HTMLView from 'react-native-htmlview'
<HTMLView value={value.excerpt.rendered} renderNode={this.renderNode} />
renderNode(node) {
if (node.name === 'img') {
const a = node.attribs
return <Image style={{ width: 400, height: 250 }} source={{ uri: a.src }} />
}
}
api all
<template>
<div>
<p>Test</p>
</div>
</template>
<script>
export default {
data() {
return {
listCategory: [],
dataCategory: {
title: null,
description: null,
data: []
},
dataArticle: {
id: null,
title: null,
image: null,
location: null,
date: null,
description: null
}
}
},
mounted() {
this.$axios.get(`https://travel-app.000webhostapp.com/wp-json/wp/v2/categories`)
.then(result => {
this.list = result.data
const listCategory = result.data.filter(item => item.count > 0)
for(let category of listCategory) {
this.dataCategory.title = category.name
this.dataCategory.description = category.description
this.listCategory.push(this.dataCategory)
this.$axios.get(`https://travel-app.000webhostapp.com/wp-json/wp/v2/posts?_embed&categories=` + category.id)
.then(result => {
for(let article of result.data) {
this.dataArticle.id = article.id
this.dataArticle.title = article.title.rendered
this.dataArticle.image = article._embedded['wp:featuredmedia'][0].source_url
this.dataArticle.location = article._embedded['wp:term'][0][0].name
this.dataArticle.date = article.date
this.dataArticle.description = article.excerpt.rendered
this.dataCategory.data.push(this.dataArticle)
}})
}
})
}
}
</script>