虽然是号称是小白初学,但本文只是对 VUE 小白,其它的基功还是有一丢丢的,不太懂的同学去看看一下详解,我这里记述的是自己的理解和观点。见谅!

        index.html:入口文件(以创建 vue3 项目的默认文件为例)

        <script type="module" src="/src/main.ts"></script>
        引入 main.ts 文件
        (index.html 中其它内容可以没,绿框中两条必需要有:创建容器、引入 main.ts)    

        src 文件夹中两个文件必不可少:main.ts 和 App.vue

        main.ts:

        import './assets/main.css'
        引入 样式表

        import { createApp } from 'vue'
        引入 createApp 用以 创建应用

        Import App from './App.vue'
        引入 App 根组件

        createApp(App).mout('#app')
        创建应用 App(根组件) 挂载 在 id 为 app 的元素中(以 #app 为容器)

        

        VUE 文件中必需要有的三个标签:
        <tmplate>
                <!-- html 代码(或是叫模板吗?)-->
        </tmplate>

        <script lang="ts">
                // js 或 ts 代码,交互 动效 的代码
                // ts 完全兼容 js,这里面写 js 代码也是可以的
                // ts 是 js 的超集
        </script>

        <style>
                /* css 样式代码 */
        </style>

        Vite 项目中, index.html 是项目的入口文件,在项目最外层。
        加载 index.html 后,Vite 解析 <script type="module" src="xxx"> 指向的 js 或 ts 文件。
        Vue3 中是通过 createApp 函数创建一个应用实例。

Logo

一站式 AI 云服务平台

更多推荐