Vue3 defines global variables

in the main.js file

import { createApp } from 'vue';

const app = createApp(App);
app.config.globalProperties.$key = "内容";// 定义全局变量
app.mount('#app');

when in use


import {getCurrentInstance} from 'vue';

export default {
  setup(){
    const { proxy } = getCurrentInstance();
    console.log(proxy.$key);
  }
}

Guess you like

Origin blog.csdn.net/YiYeZhiQiuDe_yzq/article/details/124824879
Recommended