liewife
liewife

Reputation: 51

How to initialize npm package in vue

I trying to use v-mask package in vue using npm. i run the npm install v-mask as the documentation says, but where exactly I should put in code to initialization? i tried to put it in the main.js file:

import { createApp } from 'vue'
import App from './App.vue'
import VueMask from 'v-mask'
Vue.use(VueMask);

createApp(App).mount('#app')

but get an error 'Vue' is not defined. what am I doing wrong?

Upvotes: 1

Views: 641

Answers (2)

tony19
tony19

Reputation: 138656

v-mask is built for Vue 2, so you can't use it in Vue 3 (unless you use the migration build, but that's not really intended for third party plugins).

Consider using maska, which is a masking library that supports Vue 3:

npm i -S maska

Example usage:

import { createApp } from 'vue'
import App from './App.vue'
import Maska from 'maska'

createApp(App).use(Maska).mount('#app')

demo

Upvotes: 1

Andrey Sushenkov
Andrey Sushenkov

Reputation: 1

try to save the app in a variable and execute use for app

import { createApp } from 'vue'

import App from './App.vue'
import VueMask from 'v-mask'

const app = createApp(App)
app.use(VueMask)
app.mount('#app')

Upvotes: 0

Related Questions