【发布时间】:2018-12-06 20:01:58
【问题描述】:
我设置了一个代码沙盒。任何帮助将不胜感激。
// 我的 Axios Getter 在 /year https://kom354q7r3.codesandbox.io/#/year/
methods: {
async getTDs() {
const self = this;
const response = await axios.get(
"https://s3-us-west-2.amazonaws.com/s.cdpn.io/500458/tds-data.json"
);
this.tds = response.data;
this.y2001 = response.data.y2001;
this.y2002 = response.data.y2002;
this.y2003 = response.data.y2003;
console.log(this.y2001, "this.y2001 From Year.vue");
console.log(this.y2002, "this.y2002 From Year.vue");
console.log(this.y2003, "this.y2003 From Year.vue");
}
},
mounted() {
this.getTDs();
console.log(this.tds, "From Year.vue - Before Mount");
}
我在这里获取数据并将其传递给子路由。 2001 年 / 年:
beforeMount() {
this.tds = this.$parent.y2001;
console.log(this.tds, "From y2001.vue's Parent ");
}
然后我将此数据传递给子路由上的子组件。
<TDsByYear :tds="this.tds"></TDsByYear>
// 使用来自 /Year Axios 调用的数据的子路由 https://kom354q7r3.codesandbox.io/#/year/2002
如果我访问上述子路线 (/year/2002),我在黄色框中没有得到 2002 年的任何数据,但导航到 2001 年和 2003 年确实显示了数据。
然后,如果我刷新其他子路由之一(2001 或 2003),2002 数据将显示,而我刷新的路由不显示任何数据。
如果我去主 /Years 路线并刷新,所有数据都会正确显示。
有谁知道为什么会发生这种情况以及如何解决它?我希望人们直接链接到特定路线,但重定向可能是最后的手段。
【问题讨论】:
-
请不要在标题中添加标签,并在问题描述中包含minimal reproducible example,虽然可以添加场外资源作为参考,但理解题。谢谢。
-
刚刚走出去,但会在一秒钟内发布代码。在刷新或直接访问路线时似乎是一个问题,因此认为在那里将是最重要的。
-
我不确定是什么问题?您的第一个和第三个示例似乎按预期工作,它们的实施方式有什么问题?
-
如果你直接去一个路由:kom354q7r3.codesandbox.io/#/year/2002黄色框内没有数据显示。如果我在任何其他路线上刷新也是一样的。显示其他路线数据,但不显示自己的。
-
它似乎在编辑器视图中工作,但是当您选择全屏选项时,它会显示正在发生的事情。
标签: javascript vue.js axios vue-router