Nuxt.js:How to define common method used in mounted () of component, and change data of componentWhy do we need middleware for async flow in Redux?create a component inside a component, getting error: “Failed to mount component: template or render function not defined.”How to mount dynamically single file component in Vue.jsVueJS - Accessing store data inside mountedModifying data in one component based on a state of parallel componentexported method and unexported methods in Vue.js componentvue js mounted firebase asynchronous call does not update dataDetect data changes in database using listeneraccess methods from the vue current componentVue - event listener leaks

Tile the chessboard with four-colored triominoes

The meaning of "scale" in "because diversions scale so easily wealth becomes concentrated"

Why do dragons like shiny stuff?

Is space radiation a risk for space film photography, and how is this prevented?

What does the ISO setting for mechanical 35mm film cameras actually do?

How to switch an 80286 from protected to real mode?

Identify Batman without getting caught

Does XOR'ing a random number with its inverse reduce its security if the result is a palindrome?

Why the prevalence of Tilda Swinton?

Is there a way to say "double + any number" in German?

Getting an entry level IT position later in life

Is a switch from R to Python worth it?

How and where to get you research work assessed for PhD?

Why did the US Airways Flight 1549 passengers stay on the wings?

What is the difference between these two share classes of an ETF?

How do I show and not tell a backstory?

Writing computer program code for free in an interview?

In MTG, was there ever a five-color deck that worked well?

Can attackers change the public key of certificate during the SSL handshake

What is it exactly about flying a Flyboard across the English channel that made Zapata's thighs burn?

A verb for when some rights are not violated?

How to win against ants

How can I perform a deterministic physics simulation?

Plato and the knowledge of the forms



Nuxt.js:How to define common method used in mounted () of component, and change data of component


Why do we need middleware for async flow in Redux?create a component inside a component, getting error: “Failed to mount component: template or render function not defined.”How to mount dynamically single file component in Vue.jsVueJS - Accessing store data inside mountedModifying data in one component based on a state of parallel componentexported method and unexported methods in Vue.js componentvue js mounted firebase asynchronous call does not update dataDetect data changes in database using listeneraccess methods from the vue current componentVue - event listener leaks






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I want to detect the scroll event in the mounted () of the component as follows, and change the data used in the component.



・component



<script>
import checkScroll from '~/utils/checkScroll'

export default {
...
data()
return
scrollPosition: 0

,
mounted()
window.addEventListener(
'scroll',
checkScroll(this.scrollPosition, window.scrollY)
)
,
</script>


・utils/checkScroll.js



export default function checkScroll(scrollPosition, scrollY) 
scrollPosition = scrollY



There are two issues in this case


1. I want to execute this function each time I scroll, but the function is executed only at the first scroll

2.The value of this.scrollPosition inside component does not change.


If this is the case, how will it work?










share|improve this question
































    2















    I want to detect the scroll event in the mounted () of the component as follows, and change the data used in the component.



    ・component



    <script>
    import checkScroll from '~/utils/checkScroll'

    export default {
    ...
    data()
    return
    scrollPosition: 0

    ,
    mounted()
    window.addEventListener(
    'scroll',
    checkScroll(this.scrollPosition, window.scrollY)
    )
    ,
    </script>


    ・utils/checkScroll.js



    export default function checkScroll(scrollPosition, scrollY) 
    scrollPosition = scrollY



    There are two issues in this case


    1. I want to execute this function each time I scroll, but the function is executed only at the first scroll

    2.The value of this.scrollPosition inside component does not change.


    If this is the case, how will it work?










    share|improve this question




























      2












      2








      2








      I want to detect the scroll event in the mounted () of the component as follows, and change the data used in the component.



      ・component



      <script>
      import checkScroll from '~/utils/checkScroll'

      export default {
      ...
      data()
      return
      scrollPosition: 0

      ,
      mounted()
      window.addEventListener(
      'scroll',
      checkScroll(this.scrollPosition, window.scrollY)
      )
      ,
      </script>


      ・utils/checkScroll.js



      export default function checkScroll(scrollPosition, scrollY) 
      scrollPosition = scrollY



      There are two issues in this case


      1. I want to execute this function each time I scroll, but the function is executed only at the first scroll

      2.The value of this.scrollPosition inside component does not change.


      If this is the case, how will it work?










      share|improve this question
















      I want to detect the scroll event in the mounted () of the component as follows, and change the data used in the component.



      ・component



      <script>
      import checkScroll from '~/utils/checkScroll'

      export default {
      ...
      data()
      return
      scrollPosition: 0

      ,
      mounted()
      window.addEventListener(
      'scroll',
      checkScroll(this.scrollPosition, window.scrollY)
      )
      ,
      </script>


      ・utils/checkScroll.js



      export default function checkScroll(scrollPosition, scrollY) 
      scrollPosition = scrollY



      There are two issues in this case


      1. I want to execute this function each time I scroll, but the function is executed only at the first scroll

      2.The value of this.scrollPosition inside component does not change.


      If this is the case, how will it work?







      javascript vue.js nuxt.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 4:03







      xKxAxKx

















      asked Mar 27 at 3:54









      xKxAxKxxKxAxKx

      3671 gold badge4 silver badges20 bronze badges




      3671 gold badge4 silver badges20 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0














          The first issue shouldn`t happen. if u add eventListener it will be executed every time you scroll and i have checked locally it works as expected. But you should pass a function to event listener, but you are passing already executed function.



          You could return result from it and do something like this



          export default function checkScroll(event) 
          return window.scrollY;


          mounted()
          window.addEventListener("scroll", event =>
          this.scrollPosition = checkScroll(event);
          );



          Here CBS with working example https://codesandbox.io/s/0qjkoox68v






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369550%2fnuxt-jshow-to-define-common-method-used-in-mounted-of-component-and-change%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The first issue shouldn`t happen. if u add eventListener it will be executed every time you scroll and i have checked locally it works as expected. But you should pass a function to event listener, but you are passing already executed function.



            You could return result from it and do something like this



            export default function checkScroll(event) 
            return window.scrollY;


            mounted()
            window.addEventListener("scroll", event =>
            this.scrollPosition = checkScroll(event);
            );



            Here CBS with working example https://codesandbox.io/s/0qjkoox68v






            share|improve this answer





























              0














              The first issue shouldn`t happen. if u add eventListener it will be executed every time you scroll and i have checked locally it works as expected. But you should pass a function to event listener, but you are passing already executed function.



              You could return result from it and do something like this



              export default function checkScroll(event) 
              return window.scrollY;


              mounted()
              window.addEventListener("scroll", event =>
              this.scrollPosition = checkScroll(event);
              );



              Here CBS with working example https://codesandbox.io/s/0qjkoox68v






              share|improve this answer



























                0












                0








                0







                The first issue shouldn`t happen. if u add eventListener it will be executed every time you scroll and i have checked locally it works as expected. But you should pass a function to event listener, but you are passing already executed function.



                You could return result from it and do something like this



                export default function checkScroll(event) 
                return window.scrollY;


                mounted()
                window.addEventListener("scroll", event =>
                this.scrollPosition = checkScroll(event);
                );



                Here CBS with working example https://codesandbox.io/s/0qjkoox68v






                share|improve this answer













                The first issue shouldn`t happen. if u add eventListener it will be executed every time you scroll and i have checked locally it works as expected. But you should pass a function to event listener, but you are passing already executed function.



                You could return result from it and do something like this



                export default function checkScroll(event) 
                return window.scrollY;


                mounted()
                window.addEventListener("scroll", event =>
                this.scrollPosition = checkScroll(event);
                );



                Here CBS with working example https://codesandbox.io/s/0qjkoox68v







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 14:25









                AldarundAldarund

                9,3944 gold badges36 silver badges68 bronze badges




                9,3944 gold badges36 silver badges68 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369550%2fnuxt-jshow-to-define-common-method-used-in-mounted-of-component-and-change%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해