Skip to content

注意:所有的全局配置一定要在 app.mount 之前,否在出不来效果。

全局数据

  1. Vue2

    js
    Vue.prototype.$tool = tool;
  2. Vue3

    js
    app.config.globalProperties.$tool = tool;

    组件中使用:

    js
    mport { getCurrentInstance } from "vue";
    getCurrentInstance().proxy.xxx

全局组件

  1. Vue2

    js
    Vue.component('Home', () => import('./components/Home'));
  2. Vue3

    js
    const app = createApp(App)
    app.component('Home', defineAsyncComponent(() => import('./components/Home.vue')));
    app.mount('#app');

全局中间件

  1. Vue2

    js
    Vue.use(VueRouter);
  2. Vue3

    js
    app.use(VueRouter);

基于 MIT 许可发布