mixin method is undefined in created hook of component











up vote
0
down vote

favorite












<template>

<section>
<a href="#toper" class="cd-top" v-on:click="getTemplates()">Top</a>
</section>


</template>


<script>
import api from '../../server/api.ts';

export default {
name: 'Questions',
mixins: [api],
data() {
return {
templates : getTemplates(),
};
},
created() {
// **[Vue warn]: Error in created hook: "ReferenceError: getTemplates is not defined"**
this.templates = getTemplates();
},
};
</script>


getTemplates function is working fine if i click on link but getting error in all life hooks of Vue js component.



Thanks for help in advance !










share|improve this question


























    up vote
    0
    down vote

    favorite












    <template>

    <section>
    <a href="#toper" class="cd-top" v-on:click="getTemplates()">Top</a>
    </section>


    </template>


    <script>
    import api from '../../server/api.ts';

    export default {
    name: 'Questions',
    mixins: [api],
    data() {
    return {
    templates : getTemplates(),
    };
    },
    created() {
    // **[Vue warn]: Error in created hook: "ReferenceError: getTemplates is not defined"**
    this.templates = getTemplates();
    },
    };
    </script>


    getTemplates function is working fine if i click on link but getting error in all life hooks of Vue js component.



    Thanks for help in advance !










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      <template>

      <section>
      <a href="#toper" class="cd-top" v-on:click="getTemplates()">Top</a>
      </section>


      </template>


      <script>
      import api from '../../server/api.ts';

      export default {
      name: 'Questions',
      mixins: [api],
      data() {
      return {
      templates : getTemplates(),
      };
      },
      created() {
      // **[Vue warn]: Error in created hook: "ReferenceError: getTemplates is not defined"**
      this.templates = getTemplates();
      },
      };
      </script>


      getTemplates function is working fine if i click on link but getting error in all life hooks of Vue js component.



      Thanks for help in advance !










      share|improve this question













      <template>

      <section>
      <a href="#toper" class="cd-top" v-on:click="getTemplates()">Top</a>
      </section>


      </template>


      <script>
      import api from '../../server/api.ts';

      export default {
      name: 'Questions',
      mixins: [api],
      data() {
      return {
      templates : getTemplates(),
      };
      },
      created() {
      // **[Vue warn]: Error in created hook: "ReferenceError: getTemplates is not defined"**
      this.templates = getTemplates();
      },
      };
      </script>


      getTemplates function is working fine if i click on link but getting error in all life hooks of Vue js component.



      Thanks for help in advance !







      vue.js vuejs2 mixins






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Muhammad Atif

      859414




      859414
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You forgot this for the function. Loading mixins has the same effect as if the content in it would be in your actual component. You need to call the methods the same way as you would call a local function. Always with this.



          So change it to:



          created() {
          this.templates = this.getTemplates();
          },





          share|improve this answer





















          • Thanks :) this works
            – Muhammad Atif
            2 days ago











          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',
          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%2f53373666%2fmixin-method-is-undefined-in-created-hook-of-component%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








          up vote
          1
          down vote



          accepted










          You forgot this for the function. Loading mixins has the same effect as if the content in it would be in your actual component. You need to call the methods the same way as you would call a local function. Always with this.



          So change it to:



          created() {
          this.templates = this.getTemplates();
          },





          share|improve this answer





















          • Thanks :) this works
            – Muhammad Atif
            2 days ago















          up vote
          1
          down vote



          accepted










          You forgot this for the function. Loading mixins has the same effect as if the content in it would be in your actual component. You need to call the methods the same way as you would call a local function. Always with this.



          So change it to:



          created() {
          this.templates = this.getTemplates();
          },





          share|improve this answer





















          • Thanks :) this works
            – Muhammad Atif
            2 days ago













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You forgot this for the function. Loading mixins has the same effect as if the content in it would be in your actual component. You need to call the methods the same way as you would call a local function. Always with this.



          So change it to:



          created() {
          this.templates = this.getTemplates();
          },





          share|improve this answer












          You forgot this for the function. Loading mixins has the same effect as if the content in it would be in your actual component. You need to call the methods the same way as you would call a local function. Always with this.



          So change it to:



          created() {
          this.templates = this.getTemplates();
          },






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 2 days ago









          Matthias S

          1,3161916




          1,3161916












          • Thanks :) this works
            – Muhammad Atif
            2 days ago


















          • Thanks :) this works
            – Muhammad Atif
            2 days ago
















          Thanks :) this works
          – Muhammad Atif
          2 days ago




          Thanks :) this works
          – Muhammad Atif
          2 days ago


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373666%2fmixin-method-is-undefined-in-created-hook-of-component%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

          MongoDB - Not Authorized To Execute Command

          How to fix TextFormField cause rebuild widget in Flutter

          in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith