How do you access exported vm (main vue instance) object from a component?How to call a function after vue-lazyload finishes loading?VueJs2 using stores with componentsHow do I pass AJAX data from a Vue instance to a component?Correct way to install custom VueJs PluginAdd multiple instances of a VueJS component to a template?Vuex this.$store is undefined in child componentAccessing an exported components data() in Vue.jsVue2: How to redirect to another page using routesvue-router can't access my componentshowing Vue is not defined error while importing vue-routerVue - Unable to render component

Copy previous line to current line from text file

How do I allocate more memory to an app on Sheepshaver running Mac OS 9?

Selecting elements from a list where the order is set by another list

Does XQuartz work on macOS Mojave?

Is Benjen dead?

How in the world do I place line of text EVENLY between two horizontal tikz lines?

Which US defense organization would respond to an invasion like this?

What is the closest airport to the center of the city it serves?

Is there precedent or are there procedures for a US president refusing to concede to an electoral defeat?

Dihedral group D4 composition with custom labels

Voltage Balun 1:1

Are the Night's Watch still required?

What do "Sech" and "Vich" mean in this sentence?

Nested loops to process groups of pictures

How to pass hash as password to ssh server

Would you use "llamarse" for an animal's name?

How can Internet speed be 10 times slower without a router than when using the same connection with a router?

Is it normal for gliders not to have attitude indicators?

How long would it take for people to notice a mass disappearance?

Why does sound not move through a wall?

Why did WWI include Japan?

When an imagined world resembles or has similarities with a famous world

How do I calculate how many of an item I'll have in this inventory system?

Is an HNN extension of a virtually torsion-free group virtually torsion-free?



How do you access exported vm (main vue instance) object from a component?


How to call a function after vue-lazyload finishes loading?VueJs2 using stores with componentsHow do I pass AJAX data from a Vue instance to a component?Correct way to install custom VueJs PluginAdd multiple instances of a VueJS component to a template?Vuex this.$store is undefined in child componentAccessing an exported components data() in Vue.jsVue2: How to redirect to another page using routesvue-router can't access my componentshowing Vue is not defined error while importing vue-routerVue - Unable to render component






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















If I start my vue instance from a main.js file



 //main.js
var vm = new Vue(
el: '#app',
render: h => h(App),
router,
data:


);

export
vm



app.vue itself is a router view.



<template>
<router-view></router-view>
</template>

<script>
export default
</script>


So lets say one of the components that gets loaded in the router needs access
to vm? I've gotten as far as to do this in the component:



import vm from '../main.js'


It seems to find the main.js file. But how do I then access vm? An example of a problem is when I use vue-lazyload(https://github.com/hilongjw/vue-lazyload) and need to access vm like I try here:



<template>
<div class="hero-unit-bg" v-lazy:background-image="imgUrl" >
</div>
</template>

<script>
import Vue from 'vue'
import VueLazyload from 'vue-lazyload'
import vm from '../main.js'

Vue.use(VueLazyload)
vm.$Lazyload.$on('loaded', function ( bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error , formCache)
console.log(el, src)
)
export default
name: 'HeroUnit',
data ()
return
imgUrl: 'img/hero-unit-bg.png' // String

,
methods:
,

}
</script>


Console shows vm.$Lazyload as undefined. So I don't think I'm importing vm properly. Am I missing something? Thank you.










share|improve this question




























    1















    If I start my vue instance from a main.js file



     //main.js
    var vm = new Vue(
    el: '#app',
    render: h => h(App),
    router,
    data:


    );

    export
    vm



    app.vue itself is a router view.



    <template>
    <router-view></router-view>
    </template>

    <script>
    export default
    </script>


    So lets say one of the components that gets loaded in the router needs access
    to vm? I've gotten as far as to do this in the component:



    import vm from '../main.js'


    It seems to find the main.js file. But how do I then access vm? An example of a problem is when I use vue-lazyload(https://github.com/hilongjw/vue-lazyload) and need to access vm like I try here:



    <template>
    <div class="hero-unit-bg" v-lazy:background-image="imgUrl" >
    </div>
    </template>

    <script>
    import Vue from 'vue'
    import VueLazyload from 'vue-lazyload'
    import vm from '../main.js'

    Vue.use(VueLazyload)
    vm.$Lazyload.$on('loaded', function ( bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error , formCache)
    console.log(el, src)
    )
    export default
    name: 'HeroUnit',
    data ()
    return
    imgUrl: 'img/hero-unit-bg.png' // String

    ,
    methods:
    ,

    }
    </script>


    Console shows vm.$Lazyload as undefined. So I don't think I'm importing vm properly. Am I missing something? Thank you.










    share|improve this question
























      1












      1








      1








      If I start my vue instance from a main.js file



       //main.js
      var vm = new Vue(
      el: '#app',
      render: h => h(App),
      router,
      data:


      );

      export
      vm



      app.vue itself is a router view.



      <template>
      <router-view></router-view>
      </template>

      <script>
      export default
      </script>


      So lets say one of the components that gets loaded in the router needs access
      to vm? I've gotten as far as to do this in the component:



      import vm from '../main.js'


      It seems to find the main.js file. But how do I then access vm? An example of a problem is when I use vue-lazyload(https://github.com/hilongjw/vue-lazyload) and need to access vm like I try here:



      <template>
      <div class="hero-unit-bg" v-lazy:background-image="imgUrl" >
      </div>
      </template>

      <script>
      import Vue from 'vue'
      import VueLazyload from 'vue-lazyload'
      import vm from '../main.js'

      Vue.use(VueLazyload)
      vm.$Lazyload.$on('loaded', function ( bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error , formCache)
      console.log(el, src)
      )
      export default
      name: 'HeroUnit',
      data ()
      return
      imgUrl: 'img/hero-unit-bg.png' // String

      ,
      methods:
      ,

      }
      </script>


      Console shows vm.$Lazyload as undefined. So I don't think I'm importing vm properly. Am I missing something? Thank you.










      share|improve this question














      If I start my vue instance from a main.js file



       //main.js
      var vm = new Vue(
      el: '#app',
      render: h => h(App),
      router,
      data:


      );

      export
      vm



      app.vue itself is a router view.



      <template>
      <router-view></router-view>
      </template>

      <script>
      export default
      </script>


      So lets say one of the components that gets loaded in the router needs access
      to vm? I've gotten as far as to do this in the component:



      import vm from '../main.js'


      It seems to find the main.js file. But how do I then access vm? An example of a problem is when I use vue-lazyload(https://github.com/hilongjw/vue-lazyload) and need to access vm like I try here:



      <template>
      <div class="hero-unit-bg" v-lazy:background-image="imgUrl" >
      </div>
      </template>

      <script>
      import Vue from 'vue'
      import VueLazyload from 'vue-lazyload'
      import vm from '../main.js'

      Vue.use(VueLazyload)
      vm.$Lazyload.$on('loaded', function ( bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error , formCache)
      console.log(el, src)
      )
      export default
      name: 'HeroUnit',
      data ()
      return
      imgUrl: 'img/hero-unit-bg.png' // String

      ,
      methods:
      ,

      }
      </script>


      Console shows vm.$Lazyload as undefined. So I don't think I'm importing vm properly. Am I missing something? Thank you.







      vue.js vuejs2 vue-component






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 23 at 1:42









      stormiststormist

      2,257104057




      2,257104057






















          2 Answers
          2






          active

          oldest

          votes


















          1














          You'd likely create a circular dependency by importing main.js into a component. You actually don't need to reference the root instance, as the code Vue.use(VueLazyLoad) makes the plugin accessible from any component method via this.$LazyLoad.



          For example, you could setup your code as follows:



          main.js:



          import VueLazyload from 'vue-lazyload'

          Vue.use(VueLazyload)


          App.vue



          export default 
          ...
          mounted()
          this.$Lazyload.$on('loaded', function ( bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error , formCache)
          console.log(el, src)
          )




          MyComponent.vue



          <template>
          <div v-lazy-container=" selector: 'img' ">
          <img data-src="//placekitten.com/200/200">
          <img data-src="//placekitten.com/200/201">
          <img data-src="//placekitten.com/200/202">
          </div>
          </template>


          demo






          share|improve this answer






























            1














            If you are exporting like this:



            export vm 


            then you need to import it like this:



            import vm from './module.js'


            For a default export, it would work like this:



            export default vm


            import vm from './module.js'





            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%2f55309820%2fhow-do-you-access-exported-vm-main-vue-instance-object-from-a-component%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              You'd likely create a circular dependency by importing main.js into a component. You actually don't need to reference the root instance, as the code Vue.use(VueLazyLoad) makes the plugin accessible from any component method via this.$LazyLoad.



              For example, you could setup your code as follows:



              main.js:



              import VueLazyload from 'vue-lazyload'

              Vue.use(VueLazyload)


              App.vue



              export default 
              ...
              mounted()
              this.$Lazyload.$on('loaded', function ( bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error , formCache)
              console.log(el, src)
              )




              MyComponent.vue



              <template>
              <div v-lazy-container=" selector: 'img' ">
              <img data-src="//placekitten.com/200/200">
              <img data-src="//placekitten.com/200/201">
              <img data-src="//placekitten.com/200/202">
              </div>
              </template>


              demo






              share|improve this answer



























                1














                You'd likely create a circular dependency by importing main.js into a component. You actually don't need to reference the root instance, as the code Vue.use(VueLazyLoad) makes the plugin accessible from any component method via this.$LazyLoad.



                For example, you could setup your code as follows:



                main.js:



                import VueLazyload from 'vue-lazyload'

                Vue.use(VueLazyload)


                App.vue



                export default 
                ...
                mounted()
                this.$Lazyload.$on('loaded', function ( bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error , formCache)
                console.log(el, src)
                )




                MyComponent.vue



                <template>
                <div v-lazy-container=" selector: 'img' ">
                <img data-src="//placekitten.com/200/200">
                <img data-src="//placekitten.com/200/201">
                <img data-src="//placekitten.com/200/202">
                </div>
                </template>


                demo






                share|improve this answer

























                  1












                  1








                  1







                  You'd likely create a circular dependency by importing main.js into a component. You actually don't need to reference the root instance, as the code Vue.use(VueLazyLoad) makes the plugin accessible from any component method via this.$LazyLoad.



                  For example, you could setup your code as follows:



                  main.js:



                  import VueLazyload from 'vue-lazyload'

                  Vue.use(VueLazyload)


                  App.vue



                  export default 
                  ...
                  mounted()
                  this.$Lazyload.$on('loaded', function ( bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error , formCache)
                  console.log(el, src)
                  )




                  MyComponent.vue



                  <template>
                  <div v-lazy-container=" selector: 'img' ">
                  <img data-src="//placekitten.com/200/200">
                  <img data-src="//placekitten.com/200/201">
                  <img data-src="//placekitten.com/200/202">
                  </div>
                  </template>


                  demo






                  share|improve this answer













                  You'd likely create a circular dependency by importing main.js into a component. You actually don't need to reference the root instance, as the code Vue.use(VueLazyLoad) makes the plugin accessible from any component method via this.$LazyLoad.



                  For example, you could setup your code as follows:



                  main.js:



                  import VueLazyload from 'vue-lazyload'

                  Vue.use(VueLazyload)


                  App.vue



                  export default 
                  ...
                  mounted()
                  this.$Lazyload.$on('loaded', function ( bindType, el, naturalHeight, naturalWidth, $parent, src, loading, error , formCache)
                  console.log(el, src)
                  )




                  MyComponent.vue



                  <template>
                  <div v-lazy-container=" selector: 'img' ">
                  <img data-src="//placekitten.com/200/200">
                  <img data-src="//placekitten.com/200/201">
                  <img data-src="//placekitten.com/200/202">
                  </div>
                  </template>


                  demo







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 23 at 3:23









                  tony19tony19

                  27.4k44578




                  27.4k44578























                      1














                      If you are exporting like this:



                      export vm 


                      then you need to import it like this:



                      import vm from './module.js'


                      For a default export, it would work like this:



                      export default vm


                      import vm from './module.js'





                      share|improve this answer



























                        1














                        If you are exporting like this:



                        export vm 


                        then you need to import it like this:



                        import vm from './module.js'


                        For a default export, it would work like this:



                        export default vm


                        import vm from './module.js'





                        share|improve this answer

























                          1












                          1








                          1







                          If you are exporting like this:



                          export vm 


                          then you need to import it like this:



                          import vm from './module.js'


                          For a default export, it would work like this:



                          export default vm


                          import vm from './module.js'





                          share|improve this answer













                          If you are exporting like this:



                          export vm 


                          then you need to import it like this:



                          import vm from './module.js'


                          For a default export, it would work like this:



                          export default vm


                          import vm from './module.js'






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 23 at 2:58









                          Decade MoonDecade Moon

                          14.4k32857




                          14.4k32857



























                              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%2f55309820%2fhow-do-you-access-exported-vm-main-vue-instance-object-from-a-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

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              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

                              은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현