Best practice for manually refreshing components/ emitting events #12798
Unanswered
Moaratorium
asked this question in
Help/Questions
Replies: 1 comment
-
Sorry for time Not const emit = defineEmits("checkLogin"); But const emit = defineEmits(["checkLogin"]); https://vuejs.org/api/sfc-script-setup#defineprops-defineemits |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a simple login and logout button contained inside my navbar, where the login and logout button renders conditionally based on the status of a stored username variable in local storage. Under normal conditions, various fields in the navbar are reactive but I need to manually refresh it.
Currently I'm defining the emit events
const emit = defineEmits("checkLogin");
and in the logout function
emit("checkLogin");
which calls the event in my app.vue
<Navbar :key="navKey" id="navbar" @checkLogin="loginRefresh"></Navbar>
that then calls my refresh function.
I'm relatively new at this, and while it technically does work, I'm curious if anyone here know if there is a better practice than simply changing a key to refresh a component (or perhaps simply a more correct format for the key)?
On top of this, the emitted event is throwing a warning:
[Vue warn]: Component emitted event "checkLogin" but it is neither declared in the emits option nor as an "onCheckLogin" prop.
I appreciate any feedback you have, thank you.
Beta Was this translation helpful? Give feedback.
All reactions