question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for global declaration of Vue components

See original GitHub issue

Does vue native support global component feature?

i’ve tried this code but seems it doesn’t work:

import MyComponent from './MyComponent';

Vue.component('my-component', MyComponent);

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
crollycommented, May 4, 2020

Hi @AbidKhairyAK and @icarter09 ,

since I ran into the same issue today, I came up with quite a simple workaround just using the Vue plugin capability. To register components globally, you just need to write your own little plugin like this:

import componentA from './componentA'

export default {
  // The install method is all that needs to exist on the plugin object.
  // It takes the global Vue object as well as user-defined options.
  install(Vue) {
    Vue.component('component-name', componentA)
  }
}

In your app entry file you can just use that plugin like this:

import Vue from 'vue-native-core'

import components from './src/components'
Vue.use(components)

I hope this helps, although the answer might have come a little late.

0reactions
icarter09commented, Jul 27, 2019

@AbidKhairyAK I don’t believe this is supported. Vue.component is not being picked up on as valid syntax when I tested it. I would put this down as a feature request or enhancement.

@sanketsahusoft can you add the ‘Enhancement’ label or ‘Feature Request’ label to this ticket? Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add global variable in Vue.js 3 - Stack Overflow
Is there a way to declare global variables from outside the main app creation file? In Vue 2 I used to import Vue...
Read more >
Component Registration - Vue.js
Global registration prevents build systems from removing unused components (a.k.a "tree-shaking"). If you globally register a component but end up not using it ......
Read more >
What To Do When You Need a Global Variable in Vue 3 - Telerik
A global state provided by these libraries allows you to inject it into any component in your application, making it an ideal place...
Read more >
how to make a component global in vue Code Example
in main =.js Vue.prototype.$appName = 'My App' ////in components console.log(this.$appName)
Read more >
Accessing global variables in vue components - Laracasts
Hello! I have declared some javascript variables in blade view files like this: And i need to use them in vue components:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found