// test.js
export const testFn1 = () => {
console.log('testFn1---');
}
export const testName1 = '哎呀呀呀'
// main.js
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import { testFn1, testFn, testName, testName1 } from './utils/test.js';
const app = createApp(App);
// 绑定全局方法
app.config.globalProperties.testFn1 = testFn1
// 绑定全局变量
app.config.globalProperties['testName1'] = testName1
app.use(router);
app.mount('#app');
<!-- about.vue -->
<template>
<div>about</div>
</template>
<script setup>
import { getCurrentInstance } from 'vue'
const { proxy } = getCurrentInstance()
proxy.testFn1()
console.log('testName1--', proxy.testName1);
</script>