Home >Web Front-end >Vue.js >Vite creates Vue3 projects and how Vue3 uses jsx
Vite requires Node.js version >= 12.0.0. (
node -v
Check your current node version)
Use yarn: yarn create @vitejs/app
Use npm: npm init @vitejs/app
Enter us here Project name: vite-vue3
Here select the framework we need to integrate: vue
vanilla: native js, without any framework integration
vue: vue3 framework, Only supports vue3
react: react framework
preact: lightweight react framework
lit -element: lightweight web component
svelte: svelte framework
Here we Select: vue
The project structure is very simple:
Enter the project:cd vite-vue3
Install dependencies: npm install
npm run dev Or
npx vite
or npx vite build
:
##Using jsx in Vue3
jsx cannot be used directly in the Vue3 project created by Vite. You need to introduce a plug-in to achieve it1. Install the plug-in Use yarn:import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import vueJsx from "@vitejs/plugin-vue-jsx"; // https://vitejs.dev/config/ export default defineConfig({ plugins: [vue(), vueJsx()] })
Without jsx, App.vue
<script setup> import HelloWorld from './components/HelloWorld.vue'; </script> <template> <img alt="Vue logo" src="./assets/logo.png" /> <HelloWorld msg="Hello Vue 3 + Vite" /> </template>
Using jsx, App.vue looks like this:
<script lang="jsx"> import { defineComponent } from 'vue'; import HelloWorld from './components/HelloWorld.vue'; import logo from './assets/logo.png'; export default defineComponent({ render: () => ( <div> <img alt="Vue logo" src={logo} /> <HelloWorld msg="Hello Vue 3 + Vite" /> </div> ), }); </script>
Method 2: Delete App.vue and create a new App.jsx
Create a new App.jsx file
import { defineComponent } from 'vue'; import HelloWorld from './components/HelloWorld.vue'; import logo from './assets/logo.png'; export default defineComponent({ setup () { return () => { return ( <div> <img alt="Vue logo" src={logo} /> <HelloWorld msg="Hello Vue 3 + Vite" /> </div> ) } } });Modify the introduction of main.jsimport App from './App.vue' changed to import App from './App'
import { createApp } from 'vue' import App from './App' createApp(App).mount('#app')Note Does not support eslint when saving, do eslint Verification
The above is the detailed content of Vite creates Vue3 projects and how Vue3 uses jsx. For more information, please follow other related articles on the PHP Chinese website!