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

Missing search result for setTimeout #3029

Open
michaelCTS opened this issue Sep 18, 2024 · 2 comments
Open

Missing search result for setTimeout #3029

michaelCTS opened this issue Sep 18, 2024 · 2 comments

Comments

@michaelCTS
Copy link

I'm new to Vue but have angualarJS (aka angular 1) experience and back then, anything outside of the angular scope had to be brought back into the scope for reactivity. setTimout and XHR calls were notorious for this and could get unwieldy.

Is this not an issue for VueJS anymore? My first instict was to search for setTimeout, but there are no results.

@mahmudunnabikajal
Copy link
Contributor

mahmudunnabikajal commented Sep 23, 2024

@michaelCTS
In Vue.js, you don’t need to manually bring things "back into scope" for reactivity, as Vue's reactivity system handles this much more smoothly. Vue uses a reactive data model, automatically tracking changes and propagating to the DOM.

Check this Option API example:

<template>
  <div>{{ message }}</div>
</template>

<script>
export default {
  data() {
    return {
      message: "Hello"
    };
  },
  mounted() {
    setTimeout(() => {
      this.message = "Hello, Vue!";
    }, 2000);
  }
};
</script>

In this example, Vue automatically tracks changes to the message, so when setTimeout updates this.message, the DOM will update as well. There's no need to trigger a scope digest manually.

Note: Since setTimeout is a core function of JavaScript, you can use it directly in Vue components.

@michaelCTS
Copy link
Author

Thanks for explaining @mahmudunnabikajal. I had a look at How reactivity works and understand it better now. Getters, setters and proxies didn't exist back in the days of angularjs / angular 1. Things sure have changed.

Maybe it could be useful to add a sentence to the linked document? Something along the lines of

Thanks to features introduced in ES6, dirty checks due to setTimeout and XHMLHttpRequest`, like in frameworks of old for example AngularJs (v1 of Angular), are no longer necessary.

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