admin管理员组文章数量:1333159
So, I have an API I need to retrieve data from. I'm using vue.js and axios. I have an app.vue file in which i import a ponent called Contests, in contests i'm making the api call, I'm able to retrieve the data whatsoever but it's HTML, and when I put it inside my ponent on the final screen it only shows HTML,anyone has any ideea? this is my code App ponent here
<template>
<div>
<app-contests> </app-contests>
</div>
</template>
<script>
import Contests from './ponents/Contests.vue';
export default {
ponents: {
appContests: Contests
}
}
</script>
<style>
</style>
where i'm making the api call
<template>
<div>
<div class="container">
{{info}}
</div>
<div v-if="errored">
<h1>We're sorry, we cannot retrieve this information at the moment. Please e back later.</h1>
</div>
</div>
</template>
<script>
export default {
data() {
return {
info: null
}
},
mounted() {
axios
.get('myApiThatReturnsHtml')
.then(response => {
this.info = response;
})
.catch(error => {
console.log(error);
this.errored = true
})
.finally(() => this.loading = false)
}
}
</script>
<style>
</style>
So, I have an API I need to retrieve data from. I'm using vue.js and axios. I have an app.vue file in which i import a ponent called Contests, in contests i'm making the api call, I'm able to retrieve the data whatsoever but it's HTML, and when I put it inside my ponent on the final screen it only shows HTML,anyone has any ideea? this is my code App ponent here
<template>
<div>
<app-contests> </app-contests>
</div>
</template>
<script>
import Contests from './ponents/Contests.vue';
export default {
ponents: {
appContests: Contests
}
}
</script>
<style>
</style>
where i'm making the api call
<template>
<div>
<div class="container">
{{info}}
</div>
<div v-if="errored">
<h1>We're sorry, we cannot retrieve this information at the moment. Please e back later.</h1>
</div>
</div>
</template>
<script>
export default {
data() {
return {
info: null
}
},
mounted() {
axios
.get('myApiThatReturnsHtml')
.then(response => {
this.info = response;
})
.catch(error => {
console.log(error);
this.errored = true
})
.finally(() => this.loading = false)
}
}
</script>
<style>
</style>
Share
Improve this question
asked Oct 19, 2018 at 8:19
Chris XChris X
231 silver badge3 bronze badges
1 Answer
Reset to default 7Since your response data is an HTML content, you need to use an appropriate handler to render that in DOM. Vue.js provide v-html
attribute to add HTML in DOM.
<div class="container" v-html="info">
</div>
But be careful with it because it can lead to XSS attack - https://blog.sqreen.io/xss-in-vue-js/
本文标签: javascriptGetting HTML from API in VuejsStack Overflow
版权声明:本文标题:javascript - Getting HTML from API in Vue.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742351134a2458514.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论