Using vuex inside a manually-mounted vue component Using vuex inside a manually-mounted vue component vue.js vue.js

Using vuex inside a manually-mounted vue component


Pass the store as part of the options to the constructor.

import store from "path/to/store"const MyComponent = new MyComponentConstructor({    store,    propsData: {        foo: 123,    },}).$mount('#mount-point');


I'm a little late to the party, still felt the urge to chime this in.The best approach I've found is to pass the parent key as the actual parent if you have access to it (it'll be this on the mounting parent usually). So you'll do:

const MyComponent = new MyComponentConstructor({    parent: this,    propsData: {        foo: 123,    },}).$mount('#mount-point')

You'll have access to other useful globals (like $route, $router, and of course $store) within the mounted component instance. This also properly informs Vue of the component hierarchy making MyComponent visible in the dev-tools.