这是我的代码。
export default {
components: {
draggable,
},
data() {
return {
ethPrice: null,
};
},
mounted() {
axios
.get(
"https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd"
)
.then((response) => (this.ethPrice = response.data));
回应是
{ "ethereum": { "usd": 2037.4 } }
这就是我做的模板。
<v-card-text>{{ ethPrice }}</v-card-text>
我怎样才能进入"ethereum“,然后进入"usd”,并且只获取值?
发布于 2021-07-12 21:46:44
像这样设置你的数据
ethPrice: {ethereum{usd:""}}
您需要设置它,使其保持反应性
.then((response) => (this.$set(this.ethPrice,response.data)));
然后像这样访问它
{{ethPrice.ethereum.usd}}
有关更详细的讨论,请查看reactivity https://vuejs.org/v2/guide/reactivity.html上的Vue 2指南
https://stackoverflow.com/questions/68354081
复制相似问题