/*
* getCurrentInstance: 获取上下文和全局挂载实例
* ComponentInternalInstance: 实例对象类型
*/
import { ComponentInternalInstance, getCurrentInstance } from 'vue'
export default function useCurrentInstance() {
if (!getCurrentInstance()) {
throw new Error('useCurrentInstance() can only be used inside setup() or functional components!')
}
const { appContext } = getCurrentInstance() as ComponentInternalInstance
const proxy = appContext.config.globalProperties
return {
proxy,
}
}
然后
import useCurrentInstance from '@/utils/useCurrentInstance'
const { proxy } = useCurrentInstance()
proxy.md5(form.password)
main.js
import md5 from 'js-md5'
app.config.globalProperties.md5 = md5;

博客涉及前端开发,提及main.js,结合标签推测与JavaScript、Vue.js相关,可能围绕前端项目中main.js的运用等信息技术内容。
1168

被折叠的 条评论
为什么被折叠?



