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

The data obtained through Computed vuex is undefined in onUnmounted #1928

Closed
dengyizhenfeng opened this issue Jan 22, 2021 · 2 comments
Closed

Comments

@dengyizhenfeng
Copy link

Version

4.0.0-rc.2

Reproduction link

https://github.com/dengyizhenfeng/vue3-getters-undefined

Steps to reproduce

Create a new project with the vue create command, select vuex, create a new variable {} in the state of vuex, and return a variable associated with this variable in the getters. This variable is obtained by computed in a concrete page. Under this variable it is fine if it is printed, but it is undefined if it is printed in onUnmounted

What is expected?

data from Vuex obtained through Computed can be correctly retrieved during onUnmounted

What is actually happening?

The data in Vuex obtained through computed onUnmounted is undefined

@dengyizhenfeng dengyizhenfeng changed the title Data from Vuex was not available in the Onunmounted The data obtained through Computed vuex is undefined in onUnmounted Jan 22, 2021
@kiaking
Copy link
Member

kiaking commented Jan 26, 2021

Nice catch. I've confirmed. But this happens with Vue's plain reactive as well.

import { reactive, computed, onUnmounted } from 'vue'

export default {
  setup () {
    const obj = reactive({})
    const computedObj = computed(() => obj)
    
    // If we comment out this, then the `computedObj` becomes `undefined`
    // inside `onUnmounted` hook.
    console.log(computedObj.value)

    onUnmounted(() => {
      console.log(computedObj.value)
    })
  }
}

so not Vuex problem. Couldn't find existing issue for this 🤔 Probably would close this issue here, but I'm checking if there's any existing one, or if not, we should create an issue at Vue repo. Until then, I'll keep this one open!

@kiaking
Copy link
Member

kiaking commented Jan 26, 2021

I've opened issue in Vue repo. Let's follow at here.
vuejs/core#3099

By the way, I think you should be using onBeforeUnmount instead. In this hook, the computed value is always there 👍

@kiaking kiaking closed this as completed Jan 26, 2021
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

No branches or pull requests

2 participants