BackToTech-Study / HelloVue

first steps in Vue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HelloVue - first steps in Vue

Types

  • Vue using Options
  • Vue using Composition
  • Vue in HTML
  • Vue in SCF (Single-File Components)
  • Wich one is most used !!!

Demo concepts

  • 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">

How to view output on local machine without NodeJS

  • 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 of app.js
        <script type="module">1
            import app from './app.js';
            const { createApp } = Vue;

            createApp(app).mount('#app');
        </script>
  • the app.js imports and uses the From.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.

HelloVue Generated by NPM INIT

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).

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

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:

  1. Disable the built-in TypeScript Extension
    1. Run Extensions: Show Built-in Extensions from VSCode's command palette
    2. Find TypeScript and JavaScript Language Features, right click and select Disable (Workspace)
  2. Reload the VSCode window by running Developer: Reload Window from the command palette.

Customize configuration

See Vite Configuration Reference.

Project Setup

npm install

Compile and Hot-Reload for Development

npm run dev

Type-Check, Compile and Minify for Production

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

How is everytinhg connected

  • The index.html file loads the /src/main.js file.
  • The main.js will load the App.vue
    import App from './App.vue'
  • The App.vue loads other required components

Documentation sources

About

first steps in Vue

License:MIT License


Languages

Language:Vue 81.8%Language:CSS 9.5%Language:HTML 5.5%Language:JavaScript 3.3%