Skip to content

Framework Migration

-_- edited this page Jan 14, 2025 · 82 revisions

Freelancing

Vue.js

Nuxt2

JSFiddle

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nuxt 3 Simulation in JSFiddle</title>
    <!-- Load Vue 3 via CDN -->
    <script src="https://cdn.jsdelivr.net/npm/vue@next"></script>
    <!-- Load Pinia via CDN -->
    <script src="https://cdn.jsdelivr.net/npm/pinia@next"></script>
</head>
<body>
    <div id="app"></div>
    <!-- Your custom JavaScript -->
    <script type="module">
        // Set window.__NUXT__ with cdnURL and basePath
        window.__NUXT__ = {
            cdnURL: "https://cdn.jsdelivr.net",
            basePath: "/npm/nuxt@3/"
        };

        import { createApp, ref } from 'vue';
        import { createPinia, defineStore } from 'pinia';

        // Create a Pinia store with a variable foo
        const useStore = defineStore('main', {
            state: () => ({
                foo: 'Hello from Pinia store!'
            })
        });

        // Composition API hook with a variable bar
        function useBar() {
            const bar = ref('Hello from Composition API hook!');
            return { bar };
        }

        // Create Vue app
        const app = createApp({
            setup() {
                const store = useStore();
                const { bar } = useBar();
                
                return { store, bar };
            },
            template: `
                <div>
                    <h1>{{ store.foo }}</h1>
                    <h1>{{ bar }}</h1>
                </div>
            `
        });

        // Use Pinia
        app.use(createPinia());

        // Mount app
        app.mount('#app');
    </script>
</body>
</html>

Github Issue Details

documentation:
  - name: "GitHub Issue - Extract window.__NUXT__ to <script>"
    description: "Discusses how to extract `window.__NUXT__` to a `<script>` tag for SEO purposes."
    url: "https://github.com/nuxt/nuxt/issues/8548"
    
  - name: "GitHub Issue - Remove window.__NUXT__ once app initialises"
    description: "Discusses the use of `window.__NUXT__` for backward compatibility and its removal in future versions."
    url: "https://github.com/nuxt/nuxt/issues/25336"

  - name: "Nuxt Documentation - The Context"
    description: "Explains the context object, which includes `window.__NUXT__`."
    url: "https://v2.nuxt.com/docs/internals-glossary/context/"

Clone this wiki locally