question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to reset a component?

See original GitHub issue

Currently if there’s a component I want to reinitialize, I have to include the component as an expression, set that expression to blank, then reset the expression back to the component

<div v-component="{{currentComponent}}"></div>
container.currentComponent = '';
Vue.nextTick(function () {
  container.currentComponent = 'origional-component';
});

Is there a better way to do this?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:21 (1 by maintainers)

github_iconTop GitHub Comments

157reactions
IfnotFrcommented, Jun 16, 2017

Caution, Object.assign(this.$data, this.$options.data()) does not bind the context into data(). So if you are using this into your data method you may want to apply the context with

Object.assign(this.$data, this.$options.data.apply(this))
128reactions
shammadahmedcommented, Feb 20, 2017

You can do this: Object.assign(this.$data, this.$options.data())

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a proper way of resetting a component's initial data in ...
There are three ways to reset component state: Define key attribute and change that; Define v-if attribute and switch it to false to...
Read more >
Best Practices For Resetting an ES6 React Component's State ...
Updating any field in the form updates the `state` of the form, clicking 'Cancel' should reset the form to the initial state, and...
Read more >
Preserving and Resetting State - React Docs
State is isolated between components. React keeps track of which state belongs to which component based on their place in the UI tree....
Read more >
How do I reset a component in Figma? - website builder
1. Select the component you want to reset. · 2. Click the “gear” icon in the top right corner and select “Reset Component.”...
Read more >
Using key prop to reset React components - Amit Merchant
To fix this, we can introduce the useEffect hook in the <FormComponent> component and update the internal state like so. useEffect(() => { ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found