// vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
export default defineConfig({
plugins: [vue()],
server: {
port: 3000,
open: true
}
});
// src/main.js
import { createApp } from 'vue';
import App from './App.vue';
createApp(App).mount('#app');
// src/App.vue
<template>
<div id="app">
<h1>Hello Vite + Vue!</h1>
</div>
</template>
<script>
export default {
name: 'App'
};
</script>
<style scoped>
#app {
text-align: center;
margin-top: 20px;
}
</style>
vite.config.js:
defineConfig
和 @vitejs/plugin-vue
来配置 Vite。server.port
设置开发服务器的端口为 3000。server.open
设置为 true
,表示启动时自动打开浏览器。src/main.js:
createApp
方法创建一个新的 Vue 应用实例,并挂载到 HTML 中的 #app
元素上。src/App.vue:
scoped
属性,确保样式只应用于当前组件。上一篇:vue3写法
下一篇:vue3函数式组件
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站