The process you described is correct, but you must also register the component before you can use it (within components: { ... }
).
Since you mentioned you're using vue-select
, I will use that as an example.
Step #0 - Install
As you've already done, ensure your project is initialized (npm init
), then run yarn add vue-select
/ npm i vue-select
.
Step #1 - Initialize
In your main.js
, import and register with:
import VSelect from 'vue-select';
Vue.component('v-select', VSelect);
/* rest of your Vue initialization here */
Step #2 - Use Component
<v-select :options="[{label: 'Canada', code: 'ca'}]"></v-select>
You'll also need to import the stylesheet in your CSS, with:
@import 'vue-select/src/scss/vue-select.scss';
Real Example
If you want to see a full example, I am using this package in one of my projects, I'm registering the component in my main.js
and using it ThemeSelector.vue
.
Also, if your project is large and/ or you're only using this component in one place, then a better approach would be to import it into the component that's using it. This is done in a similar way, but you must also register it under components: { ... }
for it to be accessible within your <template>
.