跳至主要內容

Vue工作随记

小企鹅工作随记Vue小于 1 分钟约 183 字...

Vue工作随记

情景

点击 编辑 跳转到编辑界面,同时编辑界面需要显示原有数据

通过 params 携带参数到编辑界面

this.$router.push({
    name: 'version-manage_edit',
    params: {
        versionNumber: params.row.versionNumber,
        platformId: params.row.platformId
    }
});

编辑界面在 created() 中,通过 this.$route.params.** 拿到数据

created() {
    if (hasObject('params.versionNumber', this.$route) && this.$route.params.versionNumber !== null &&
        hasObject('params.platformId', this.$route) && this.$route.params.platformId !== null) {
        this.versionNumber = this.$route.params.versionNumber;
        this.platformId = this.$route.params.platformId;
        this.isEdit = true;
        this.getVersion();
    }
}

情景

getVersion 中使用了 getPlatforms 赋值的变量,但由于 getPlatforms 中的请求是异步的,导致赋值的变量没来得及初始化,报错 TypeError: Cannot read properties of undefined

created() {
    this.getPlatforms();
    this.getVersion();
}

created 声明为异步方法,并在 getPlatforms 前加上 wait

async created() {
    await this.getPlatforms();
    this.getVersion();
}
上次编辑于:
你认为这篇文章怎么样?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
评论
  • 按正序
  • 按倒序
  • 按热度