Socket
Book a DemoInstallSign in
Socket

vue-force-next-tick

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-force-next-tick

A Vue implantation of the double requestAnimationFrame method to force nextTick()

1.2.0
latest
Source
npmnpm
Version published
Weekly downloads
1.5K
17.92%
Maintainers
1
Weekly downloads
 
Created
Source

VueForceNextTick

When you need to ensure the DOM has been updated Vue's nextTick just doesn't work. You will need to use the double requestAnimationFrame method. This is an elegant wrapper to allow you to use the double requestAnimationFrame method within your Vue applications either globally Vue.$forceNextTick(callback) or within a method this.$forceNextTick(callback)

Table of contents

  • VueForceNextTick
  • Installation
  • Default import
  • A bit of History
  • Usage
  • Example Vue Component

Installation

npm i vue-force-next-tick

# or

yarn add vue-force-next-tick

Default import

import Vue from 'vue'
import VueForceNextTick from 'vue-force-next-tick'
Vue.use(VueForceNextTick)

A bit of History

How does double requestanimationframe work

VueJS: How to wait for a browser re-render? Vue.nextTick doesn't seem to cover it.

Inspired by the advice of [Justineo] (https://github.com/Justineo)

Usage

Global Example

Vue.$forceNextTick(() => {
  // Your code here.
})

// or 

await Vue.$forceNextTick()

Within a component

methods: {
  yourMethod () {
    this.$forceNextTick(() => {
      // Your code here.
    })
  }
  
  // or 
  
  async yourMethod () {
    await this.$forceNextTick()
    // Your code here.
  }
}

EXAMPLE VUE COMPONENT

<template>
  <button
    @click="doSomethingBig"
  >
    Lets count to 10 million!
  </button>
</template>

<script>
export default {
  data () {
    return {
      loading: false,
      done: false
    }
  },
  methods: {
    doSomethingBig () {
      this.loading = true
      this.$forceNextTick(() => {
        for (var i = 1; i<10000000; ++i){
        	this.done = !i
        }
        this.done = true
        this.loading = false
      })
    }
  }
}
</script>

Keywords

vue

FAQs

Package last updated on 06 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.