// vite.config.ts
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import path from 'path';
export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
});
// src/main.ts
import { createApp } from 'vue';
import App from './App.vue';
createApp(App).mount('#app');
// src/App.vue
<template>
<div id="app">
<h1>Hello Vite + Vue + TypeScript!</h1>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'App',
});
</script>
<style scoped>
#app {
text-align: center;
margin-top: 20px;
}
</style>
vite.config.ts:
defineConfig
函数来配置 Vite。@vitejs/plugin-vue
插件以支持 Vue 单文件组件(SFC)。@
指向 src
目录,方便在项目中引用模块。src/main.ts:
createApp
函数创建一个 Vue 应用实例,并挂载到 DOM 元素 #app
上。src/App.vue:
defineComponent
来定义组件,确保类型安全。scoped
属性,使样式仅应用于当前组件。上一篇:vue2 ref
下一篇:vue 插件
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站