Skip to content

Vue3 细节变化

分类:Vue3
标签:VueWeb 前端
创建时间:2022年01月13日 10:11:09

注意:所有的全局配置一定要在 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 许可发布