做类似百度云盘中返回的功能

双击文件名称进入下一级的内容,需要点击返回按钮返回。多级情况下做返回。返回的时候根据parentId去做判断。

双击文件夹的时候,将文件的parentId存入到一个空数组中,因为文件的第一级的id是0,所以数组中初始化的时候是要有一个0的。然后就是每次双击都会将parentId存入数组中,返回的时候就根据数组中的id去判断请求数据。我这里数组的名字是 oldPrrentIdList

nextFolder(fileId, fileType) {
            this.num++;
            this.fileType = fileType;
            this.fileId = fileId;
            if (fileType == 0) {
                this.temp = [];
                this.oldParentId = this.queryForm.parentId;
                if (fileId == 0) {
                    this.queryForm.fileType = 0;
                    this.queryForm.parentId = undefined;
                } else {
                    this.queryForm.fileType = undefined;
                    this.queryForm.parentId = fileId;
                    this.oldPrrentIdList.push(fileId);
                }
                console.log(this.oldPrrentIdList, 'this.oldPrrentIdList');
                this.getList(this.temp);
            }
},
backParent() {
    if (!this.$route.params.val) {
        this.temp = [];
        this.countNum++;
        if (this.oldPrrentIdList.length > 1 && this.countNum == 1) {
            this.oldPrrentIdList.splice(this.oldPrrentIdList.length - 1, 1);
        }
        if (this.oldPrrentIdList.length > 1) {
            this.queryForm.parentId = this.oldPrrentIdList[this.oldPrrentIdList.length - 1];
            this.oldPrrentIdList.splice(this.oldPrrentIdList.length - 1, 1);
            console.log(this.oldPrrentIdList, '1');
        } else if (this.oldPrrentIdList.length == 1) {
            this.queryForm.parentId = 0;
        }
        if (this.queryForm.parentId == 0) {
            this.temp = [{
                imgSrc: file,
                title: '收藏夹',
                checkModel: false,
                fileType: 0,
                showModel: true,
                id: 0,
                fileLabelArray: null
            }];
        }
        this.queryForm.fileType = undefined;
        this.getList(this.temp);
    } else {
        this.getFile();
    }
},
原文地址:https://www.cnblogs.com/florazeng/p/13579774.html