这里以引入faker.js为例
先于main.ts文件中注册全局变量
import { faker } from '@faker-js/faker';
import { createApp } from 'vue'
const app=createApp(App)
app.config.globalProperties.$faker = faker
faker.setLocale('zh_CN')
app.mount('#app')
使用setLocale方法是生成假数据为中文
在组件中使用,需要对引入增加断言,不然会报错
import { getCurrentInstance } from "vue";
const{proxy}=getCurrentInstance() as any ;
console.log(proxy.$faker.name.fullName());
然后即可在控制台查看结果