Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决 upload 组件异步赋值 default-file-list 导致 this.uploadList = this.$refs.upload.fileList 指向丢失的问题。 #960

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kiccer
Copy link

@kiccer kiccer commented Sep 10, 2021

@kiccer
Copy link
Author

kiccer commented Sep 10, 2021

这里留言给遇到相同问题的朋友,在此PR被合并之前,还有一个方法规避这个问题的发生:
在异步赋值 default-file-list 之后,重新执行一次 this.uploadList = this.$refs.upload.fileList 就可以拿到最新的引用地址。

@kiccer
Copy link
Author

kiccer commented Sep 10, 2021

举个例子:

export default {
    data () {
        return {
            uploadList: [],
            defaultFileList: []
        }
    },

    mounted () {
        this.uploadList = this.$refs.upload.fileList
    },

    methods: {
        getData () {
            axios.get('path/to/remote/api', {
                params: {}
            }).then(res => {
                // console.log(res)
                this.defaultFileList = res.file_list
                this.$nextTick(() => {
                    this.uploadList = this.$refs.upload.fileList
                })
            })
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant