3.1 KiB
Development Example
This article is based onVite Project example to show how to useTinyVue
components.
Building the Vite project
Create aVite
Works:
yarn create vite
#or
npm init vite@latest
CreatedVite
Go to the project directory and run the following commands to download and start the project:
yarn
#or
npm install
yarn dev
#or
npm run dev
After the browser is started, if the following interface is displayed, it indicates thatVite
The project is started successfully.
Install and useTinyVue
Components
Run the following command to install theVue 3.0
version ofTinyVue
Component library:
yarn add @opentiny/vue@3
#or
npm install @opentiny/vue@3
Then modify thevite.config.js
, add the following code highlighted section:
//vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [vue()],
define: {
'process.env': { ...process.env }
}
})
When the installation is complete, pressCtrl + C
Interrupt the current service, and then performyarn dev #npm run dev
Restart the service.
Next, modify theApp.vue
file, add the section highlighted by the following code (in theButton
Component as an example):
<script setup>
//This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
import HelloWorld from './components/HelloWorld.vue'
import { Button as TinyButton } from '@opentiny/vue'
</script>
<template>
<img alt="Vue logo" src="@demos/resource/logo.png" />
<HelloWorld msg="Hello Vue 3 + Vite" />
<TinyButton type="success">Button</TinyButton>
</template>
<style>
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
</style>
in the above writing<script setup>
is in the single file componentSFC
Combinations used in the mediumAPI
Compiler syntax. For details, see.Vue official website .
If you are not familiar with the above syntax, you can also use the standardSFC
Format:
<template>
<TinyButton type="success">Button</TinyButton>
</template>
<script>
import { Button } from '@opentiny/vue'
export default {
components: {
TinyButton: Button
}
}
</script>
Alternatively, a single component can be used.TinyVue
Components:
<template>
<TinyButton type="success">Button</TinyButton>
</template>
<script>
import Button from '@opentiny/vue-button'
export default {
components: {
TinyButton: Button
}
}
</script>
The green button shown below should appear on the browser interface, indicating thatTinyVue
The component has been introduced and takes effect.