【发布时间】:2020-07-10 02:28:35
【问题描述】:
我正在尝试使用 vue-cli 和从数组的 JSON 对象中按国家/地区获取 Covid-19 案例的路由器创建一个简单的。这是我的第一个 Vue 应用程序。但是,我不断收到有关“声明反应性属性”的错误。我在许多不同的论坛上搜索了几十个类似的错误,似乎成功了。
大部分code is from vue.org,JSON 链接除外。
Api.js:
import axios from "axios";
import Vue from "vue";
new Vue({
el: "#app",
data() {
return {
info: null,
loading: true,
errored: false
};
},
template: "<div>{{ output.info }}</div>",
mounted() {
axios
.get("https://pomber.github.io/covid19/timeseries.json")
.then(response => {
this.info = response.data;
console.log(this.info);
})
.catch(error => {
console.log(error);
this.errored = true;
})
.finally(() => (this.loading = false));
}
});
export default {
name: "About",
props: {
loading: String,
errored: String,
info: String
}
};
关于.js
<template>
<h1>Covid-19 cases by Country</h1>
<section v-if="errored">
<p>
We're sorry, we're not able to retrieve this information at the moment,
please try back later
</p>
</section>
<section v-else>
<div v-if="loading">Loading...</div>
<div v-else v-for="data in info" :key="data" class="currency">
<h1>{{ data.Portugal[0].deaths }}</h1>
</div>
</section>
错误:
[Vue 警告]:属性或方法“错误”未在 实例,但在渲染期间引用。确保该属性是 反应式,无论是在数据选项中,还是对于基于类的组件,通过 初始化属性
我可以看到警告 3 次,对于每个错误的道具,加载和信息,最重要的一个。
【问题讨论】:
-
错误是字符串还是布尔值?
-
@ChristianCarrillo 应该是布尔值,我改了但同样的错误。
标签: vue.js vue-router