-
Notifications
You must be signed in to change notification settings - Fork 344
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
Debugging component state when using render-in-setup pattern #514
Comments
/cc @pikax is https://github.com/pikax/vue-composable#inspector |
Not yet, devtools beta doesn't support Vue 2 AFAIR @LachlanStuart that's not possible one way to do it would be with something like vuejs/rfcs#210 The reason why is because refs are not exposed |
@antfu @pikax Thanks for the links. I'll keep an eye on those. Unfortunately I'm stuck on Vue 2 for the time being. I feel it's possible to make an automatic solution at the framework level (i.e. through changes to the @vue/composition-api plugin). In dev mode, when Do you think it would be reasonable to implement it at this level of the stack? If I made a PR, would it be considered for inclusion? |
@LachlanStuart that wouldn't be up to spec with vue3, you can open an RFC to discuss that inclusion. one easy way is having a composable: function expose(obj) {
const instance = getCurrentInstance()
instance.$nextTick(()=> Object.keys(obj).forEach(x=> this._data[x] = obj[x])
}
setup(){
const text = ref('text')
expose({text})
return ()=> h('div', text.value)
}
|
Stale issue message |
@LachlanStuart did you get a solution to this? |
@hisuwh No. I didn't have time to pursue the suggested RFC process, and haven't actually worked much with Vue since then. |
When returning a render function from setup(), usually all component state will be held in local
ref
/reactive
variables inside thesetup
function. The problem is that these variables are inaccessible in the Vue.js devtools. e.g. there's no easy way to inspect the contents ofstate.counter
in the following:With all other patterns, devtools would be able to access the variables at runtime in the component's
$data
. However, not only are theref
/reactive
variables not registered against the component,data()
occurs aftersetup()
in the lifecycle, so there's no hacky workaround like doingthis.$data.state = state
insetup()
. The only quick way to view these variables is to dowatch(() => console.log(state))
, but this can be extremely spammy, and is hard to read if there are multiple instances of the component.Am I missing any other solutions? Are there any plans to make these hidden state containers accessible in devtools? I doubt it's possible to save variable names, but it seems like it should be possible for
ref()
/reactive()
to callgetCurrentInstance()
and somehow associate the returned observable with the component...The text was updated successfully, but these errors were encountered: