vue3 学习笔记01 -- 搭建项目及基础配置

vue3 学习笔记01 – 搭建项目及基础配置

确保你已经安装了Node.js(建议使用最新的LTS版本)

搭建项目

  • 初始化项目
如果选择npm创建项目再执行
npm create vite@latest my-vue3-app --template vue-ts

使用yarn,如果电脑没有安装yarn cnpm i yarn -g
 
yarn create vite my-vue3-app --template vue-ts
使用pnpm:如果电脑尚未安装 pnpm cnpm i pnpm -g
 
pnpm create vite my-vue3-app --template vue-ts
  • 进入项目文件夹
cd my-vue3-app
  • 安装依赖
npm install
  • 启动项目
npm run dev
  • 项目目录
    在这里插入图片描述

  • 访问页面
    在这里插入图片描述

基础配置 – vite.config.ts

  • 使用ip访问
export default defineConfig({
  plugins: [vue()],
  server:{
    host: '0.0.0.0' // 允许IP访问
  },
   resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
})
  • resolve.alias 别名

    • 安装 @types/node
    npm install --save-dev @types/node
    
    • 在tsconfig.json中配置,确认 TypeScript 配置正确
      在这里插入图片描述

    • vite.config.js中配置

          import { fileURLToPath, URL } from 'node:url'
          export default defineConfig({
          plugins: [vue()],
          resolve: {
              alias: {
                  '@': fileURLToPath(new URL('./src', import.meta.url))
                 }
              },
          })
      
  • 打开src/mian.ts发现在引入 App.vue中画红线,说明项目中没有.vue的声明文件,需要自行补充一下

src/types/env.d.ts
/// <reference types="vite/client" />
declare module '*.vue' {
  import { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}

相关推荐

  1. vue-cli项目一些打包配置

    2024-07-11 09:36:06       51 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 09:36:06       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 09:36:06       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 09:36:06       57 阅读
  4. Python语言-面向对象

    2024-07-11 09:36:06       68 阅读

热门阅读

  1. Spring Boot常用注解类

    2024-07-11 09:36:06       24 阅读
  2. Perl伪哈希探秘:深入理解Perl中的高级数据结构

    2024-07-11 09:36:06       22 阅读
  3. Python:引号应用、字符串应用

    2024-07-11 09:36:06       23 阅读
  4. Hadoop之HDFS重点架构原理简介

    2024-07-11 09:36:06       23 阅读
  5. Spark SQL----ALTER DATABASE

    2024-07-11 09:36:06       20 阅读
  6. SpringBoot3+Redis实现分布式锁

    2024-07-11 09:36:06       18 阅读
  7. 五种常见排序算法

    2024-07-11 09:36:06       19 阅读
  8. uniapp 防止重复提交数据

    2024-07-11 09:36:06       21 阅读
  9. 通过实例说明.NET Autofac依赖注入的多种方式

    2024-07-11 09:36:06       22 阅读
  10. .NET 9 预览版 5 发布

    2024-07-11 09:36:06       26 阅读
  11. 【Android12】第三方APP开机自启

    2024-07-11 09:36:06       24 阅读
  12. 深入理解CSS中的透明效果实现

    2024-07-11 09:36:06       17 阅读
  13. mac查看31295端口被占

    2024-07-11 09:36:06       21 阅读
  14. 简述框架和函数库的区别

    2024-07-11 09:36:06       22 阅读