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;
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
add a comment |
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
add a comment |
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
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
vue.js vuejs2 vue-component
asked Mar 23 at 1:42
stormiststormist
2,257104057
2,257104057
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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
add a comment |
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'
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 23 at 3:23
tony19tony19
27.4k44578
27.4k44578
add a comment |
add a comment |
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'
add a comment |
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'
add a comment |
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'
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'
answered Mar 23 at 2:58
Decade MoonDecade Moon
14.4k32857
14.4k32857
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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