如何在Vue中更改道具时调用Axios? [英] How do I call Axios on prop change in Vue?
本文介绍了如何在Vue中更改道具时调用Axios?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
关于值 id
的更改,我想通过Axios进行JSON调用并更新页面的必要部分.我怎么做?目前,我已 mount
和 activated
,它们似乎无法正常工作...
On the change of the value id
, I would like to make a JSON call via Axios and update necessary parts of the page. How do I do that? Currently, I have mounted
and activated
and they do not seem to be working...
代码:
const Home = {
template: `
<div class="user">
<h2>user {{ id }}</h2>
<h2>{{ info }}</h2>
bet
</div>
`,
props: {
id: {
type: String,
default: 'N/A'
}
},
data () {
return {
info: null
}
},
activated () {
axios
.get('https://api.coindesk.com/v1/bpi/currentprice.json',
{ params: { id: id }}
)
.then(response => (this.info = response))
},
mounted() {
axios
.get('https://api.coindesk.com/v1/bpi/currentprice.json')
.then(response => (this.info = 'response'))
}
}`
推荐答案
查看全文