【发布时间】:2018-08-20 12:23:44
【问题描述】:
我有一个组件,其中包含指向同一路由的路由器链接,但参数不同。导航到这些链接时,网址会更改,但数据不会更新。我已经定义了 beforeRouteUpdate,但它从未被调用过。
import Vue from 'vue';
import { Component } from 'vue-property-decorator';
@Component
export default class AccountComponent extends Vue {
address: string;
account: Account;
data() {
return {
account: null
}
}
beforeRouteUpdate(to: any, from: any, next: any) {
console.log('beforeRouteUpdate for ' + to.params.address);
next();
}
mounted() {
this.address = this.$route.params.address;
this.loadData();
}
loadData() {
console.log('Fetching data for ' + this.address);
fetch('api/Account/Get?address=' + this.address)
.then(response => response.json() as Promise<Account>)
.then(data => {
this.account = data;
});
}
}
【问题讨论】:
标签: typescript vuejs2 vue-component vue-router