S
S
sirinotapple2022-03-05 13:03:25
Vue.js
sirinotapple, 2022-03-05 13:03:25

Is it possible to pass a pointer to a vue variable into a directive?

Hello, I want to create a universal directive that changes the component variable specified when the directive is called
. For example

v-scrollDeploy:isDeployed

directives: {
    scrollDeploy: {
      mounted(el, binding) {
        window.addEventListener("scroll", () => {
          if (window.scrollY < el.offsetHeight) {
            binding.instance[binding.arg] = true;
          } else {
            binding.instance[binding.arg] = false;
          }
        });
        window.dispatchEvent(new Event("scroll"));
      },
    },
  },

The bottom line is that, regardless of the number of calls to the directive, it changes the state of any variable passed to it, and not just this.isDeployed as in the case above ... How can I implement this

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question