列:
function fun(){
console.log('这是工具函数')
return 888
}
挂载到全局方法
main.js
const app = createSSRApp(App)
app.config.globalProperties.$util = fun
在template中使用时,可以直接使用
<div>{{$util}}</div>
在script中使用,需要获取到 getCurrentInstance实例再进行使用
import {getCurrentInstance} from 'vue'
const { proxy } = getCurrentInstance()
console.log('$util::', proxy.$util()); //888