simple-component-vue3 v0.2.10
simple-component-vue3
This template should help get you started developing with Vue 3 in Vite.
Recommended IDE Setup
VSCode + Volar (and disable Vetur) + TypeScript Vue Plugin (Volar).
Type Support for .vue
Imports in TS
TypeScript cannot handle type information for .vue
imports by default, so we replace the tsc
CLI with vue-tsc
for type checking. In editors, we need TypeScript Vue Plugin (Volar) to make the TypeScript language service aware of .vue
types.
If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a Take Over Mode that is more performant. You can enable it by the following steps:
- Disable the built-in TypeScript Extension
1) Run
Extensions: Show Built-in Extensions
from VSCode's command palette 2) FindTypeScript and JavaScript Language Features
, right click and selectDisable (Workspace)
- Reload the VSCode window by running
Developer: Reload Window
from the command palette.
Customize configuration
See Vite Configuration Reference.
Project Setup
npm install
To install web component into your project you need to initialize it inside
index.html (vanilla js or vue)
<script type="module">
import {register} from "path_to/simple-component-vue3/dist/index.js"
register()
</script>
index.js (react root script)
import {register} from "path_to/simple-component-vue3/dist/index.js"
register()
vue can also initialize it inside
main.js/ts script
import {register} from "path_to/simple-component-vue3/dist/index.js"
register()
USAGE
First component is direct which gets msg as property in vue.
<simple-component-vue3-direct msg="something"></simple-component-vue3-direct>
Second component is non-direct which gets msg as property in vue.
<simple-component-vue3-ref msg="something"></simple-component-vue3-ref>
Third component is emit does not work right now
<simple-component-vue3-emit></simple-component-vue3-emit>
Fourth component is vmodel which creates input field that shows input below it.
<simple-component-vue3-vmodel></simple-component-vue3-vmodel>
Fifth component is broadcast which uses broadcast channel. Declaration of BroadcastChannel in your project should be like this with 'test-channel' name required
// Declaration
const bc = new BroadcastChannel('test-channel')
// Usage
bc.onmessage = (event) => {
console.log(event.data);
}
// even.data gets object of data sent from vue component (parameters: type, title)
To use component declare it like this.
<simple-component-vue3-broadcast></simple-component-vue3-broadcast>
Component creates input field which value is broadcasted via BroadcastChannel .data object is holding input value in parameter "title"
Compile and Hot-Reload for Development
npm run dev
Type-Check, Compile and Minify for Production
npm run build