【发布时间】:2019-01-12 17:41:33
【问题描述】:
在更改id 值时,我想通过 Axios 进行 JSON 调用并更新页面的必要部分。我怎么做?目前,我有mounted 和activated,它们似乎没有工作......
代码:
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'))
}
}`
【问题讨论】:
标签: javascript vue.js axios