Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

vue3+ts+vite

作者:你不爱我就滚。   发布日期:2025-07-04   浏览:32

// src/main.ts
import { createApp } from 'vue'
import App from './App.vue'

const app = createApp(App)

app.mount('#app')

// src/App.vue
<template>
  <div id="app">
    <h1>Hello Vue 3 with TypeScript and Vite!</h1>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'App',
})
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
})

// tsconfig.json
{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "strict": true,
    "jsx": "preserve",
    "importHelpers": true,
    "moduleResolution": "node",
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "baseUrl": ".",
    "types": [
      "webpack-env"
    ],
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "ESNext",
      "DOM"
    ]
  },
  "include": [
    "src/**/*.ts",
    "src/**/*.d.ts",
    "src/**/*.tsx",
    "src/**/*.vue"
  ]
}

解释说明

  1. main.ts:

    • 使用 createApp 函数创建 Vue 应用实例,并将其挂载到 DOM 元素上。
  2. App.vue:

    • 这是一个单文件组件(SFC),包含模板、脚本和样式。
    • 使用 defineComponent 来定义组件,确保类型安全。
  3. vite.config.ts:

    • 配置 Vite 构建工具,使用 @vitejs/plugin-vue 插件来支持 Vue 单文件组件。
  4. tsconfig.json:

    • 配置 TypeScript 编译选项,确保项目中的 TypeScript 文件能够正确编译。
    • 设置了路径别名 @ 指向 src 目录,简化导入路径。

上一篇:vue 3.0

下一篇:vue图标

大家都在看

vue.config.js configu

node.js vue

vue 图表组件

vue3watch监听多个变量

vue查看版本

vue3 reactive对象重新赋值

vue等待几秒

vue3 setup computed

vue screenfull

vue json.stringify

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站