首页 前端知识 VUE3——003、VUE 项目中的文件结构(index.html、main.ts、App.vue)

VUE3——003、VUE 项目中的文件结构(index.html、main.ts、App.vue)

2024-09-30 23:09:24 前端知识 前端哥 76 333 我要收藏

        虽然是号称是小白初学,但本文只是对 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 函数创建一个应用实例。

转载请注明出处或者链接地址:https://www.qianduange.cn//article/18829.html
标签
评论
发布的文章

JSON简介

2024-09-30 23:09:25

Node.js和npm的安装及配置

2024-09-30 23:09:02

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!