vue3 quasar in typescript

To use Vue 3 with Quasar in TypeScript, you can follow these steps:

  1. Create a new Quasar project with TypeScript option enabled:

    quasar create my-project --type typescript
    
    43 chars
    2 lines
  2. Install Vue 3:

    npm install vue@next
    
    21 chars
    2 lines
  3. Install Quasar:

    npm install @quasar/app
    
    24 chars
    2 lines
  4. Install Vue Router and Vuex:

    npm install vue-router@4 vuex@4
    
    32 chars
    2 lines
  5. Create a tsconfig.json file in the root of your project:

    {
      "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "strict": true,
        "jsx": "preserve",
        "moduleResolution": "node",
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "noImplicitReturns": true,
        "noImplicitThis": true,
        "noImplicitAny": true,
        "lib": ["esnext", "dom", "dom.iterable", "scripthost"]
      }
    }
    
    400 chars
    17 lines
  6. Create a shims-vue.d.ts file in the src folder:

    index.ts
    declare module "*.vue" {
      import { defineComponent } from "vue";
      const component: ReturnType<typeof defineComponent>;
      export default component;
    }
    
    151 chars
    6 lines
  7. Modify the src/main.ts file to use Vue 3:

    index.ts
    import { createApp } from "vue";
    import App from "./App.vue";
    import router from "./router";
    import store from "./store";
    
    const app = createApp(App);
    app.use(router);
    app.use(store);
    app.mount("#app");
    
    203 chars
    10 lines
  8. Modify the src/router/index.ts file to use Vue Router 4:

    index.ts
    import { createRouter, createWebHistory } from "vue-router";
    import Home from "../views/Home.vue";
    
    const routes = [
      {
        path: "/",
        name: "Home",
        component: Home,
      },
    ];
    
    const router = createRouter({
      history: createWebHistory(process.env.BASE_URL),
      routes,
    });
    
    export default router;
    
    303 chars
    18 lines
  9. Modify the src/store/index.ts file to use Vuex 4:

    index.ts
    import { createStore } from "vuex";
    
    export default createStore({
      state: {},
      mutations: {},
      actions: {},
      modules: {},
    });
    
    130 chars
    9 lines

That's it! You can now use Vue 3 with Quasar in TypeScript.

gistlibby LogSnag