- Vuew is A framework
- follow tutorial - https://vuejs.org/tutorial/#step-1
- Vue using Options
- Vue using Composition
- Vue in HTML
- Vue in SCF (Single-File Components)
- Wich one is most used !!!
- Declarative Rendering
- Event Listeners
- Form Bindings
- Conditional Rendering
- List Rendering
- Computed Property
- Lifecycle and Template Refs
- Watchers
- Components
- Slots
- Emits can be used to call a callback function defined in the parent
<script>
function handleRemove(todo) {
console.log(`removed: ${todo.id} - ${todo.text}`);
}
</script>
....
<List :todosParam = todoList @remove = "handleRemove" />
removeTodo(todo) {
this.todos.splice(this.todos.indexOf(todo), 1)
this.$emit('remove', todo)
}
- Attribute Bindings (passing props to a component). Implemented using
v-bind:
or short:
<List :todos = "[ { id: 1, text: 'Learn HTML' }, { id: 2, text: 'Learn JavaScript' }, { id: 3, text: 'Learn Vue' }]" />
- Props Component parameters are received with
props
props: {
todos: Array
},
- Props are read only. You can save them in local variable
props: {
todosParam: Array
},
data() {
return {
newTodo: '',
todos: this.todosParam
}
},
-
v-model
used as 2 way binding
<input v-model="newTodo">
- You must have an entry point in the application (in our case
index.html
) index.html
must load VueJS via a CDN (content delivery network) or hosted localy (downside is we don't get any new features and updates)- To bypas CORS regulations when loading local files via import in pure JS we need a local server (I recomend Live Server plugin for VS Code)
- To view output just start the
index.html
page in Live server. - the
index.html
file will load the content ofapp.js
<script type="module">1
import app from './app.js';
const { createApp } = Vue;
createApp(app).mount('#app');
</script>
- the
app.js
imports and uses theFrom.js
import Form from "./Form.js"
...
<div><Form></Form></div>
- In this case the
Form.js
file was created by hand (hard coded). The browser does not know about the .vue extension.
This template should help get you started developing with Vue 3 in Vite.
VSCode + Volar (and disable Vetur) + TypeScript Vue Plugin (Volar).
- Is a VSCode plugin that offers vue language support
- Volar uses petite-vue, an alternative distribution of Vue optimized for progressive enhancement.
- Volar also supports Static Site Generation using VitePress
- VitePress is currently in alpha status. It is already suitable for out-of-the-box documentation use, but the config and theming API may still change between minor releases.
- Vite is a lightweight and fast build tool with first-class Vue SFC support. It is created by Evan You, who is also the author of Vue!
- Vue CLI is the official webpack-based toolchain for Vue. It is now in maintenance mode and we recommend starting new projects with Vite unless you rely on specific webpack-only features. Vite will provide superior developer experience in most cases.
- in this example the vite configuration information is stored in the
vite.config.js
file
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
- Run
Extensions: Show Built-in Extensions
from VSCode's command palette - Find
TypeScript and JavaScript Language Features
, right click and selectDisable (Workspace)
- Run
- Reload the VSCode window by running
Developer: Reload Window
from the command palette.
See Vite Configuration Reference.
npm install
npm run dev
npm run build
Run Unit Tests with Vitest
npm run test:unit
###3 Run End-to-End Tests with Cypress
npm run build
npm run test:e2e # or `npm run test:e2e:ci` for headless testing
Lint with ESLint
npm run lint
- The
index.html
file loads the/src/main.js
file. - The
main.js
will load theApp.vue
import App from './App.vue'
- The
App.vue
loads other required components
- https://vuejs.org/guide/scaling-up/tooling.html
- https://github.com/johnsoncodehk/volar
- https://github.com/vuejs/petite-vue
- https://vitejs.dev/
- https://medium.com/js-imaginea/the-vue-js-internals-7b76f76813e3
- https://vitejs.dev/guide/ (If you want to dig deeper take a look at vite templates)
- https://webpack.js.org/concepts/