[英]How to initialize npm package in vue
I trying to use v-mask package in vue using npm.我尝试使用 npm 在 vue 中使用v-mask package。 i run the npm install v-mask
as the documentation says, but where exactly I should put in code to initialization?如文档所述,我运行npm install v-mask
,但是我应该在哪里输入初始化代码? i tried to put it in the main.js file:我试图把它放在 main.js 文件中:
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.但得到一个错误'Vue'未定义。 what am I doing wrong?我究竟做错了什么?
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). v-mask
是为 Vue 2 构建的,因此您不能在 Vue 3 中使用它(除非您使用迁移构建,但这并不是真正适用于第三方插件)。
Consider using maska
, which is a masking library that supports Vue 3:考虑使用maska
,它是一个支持 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')
try to save the app in a variable and execute use
for app尝试将应用程序保存在变量中并为应用程序执行use
import { createApp } from 'vue'
import App from './App.vue'
import VueMask from 'v-mask'
const app = createApp(App)
app.use(VueMask)
app.mount('#app')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.