Vue learning – Encounter Vue. Js

Vue. Js

Know the vue

Why learn VUE

A brief introduction to VUE

Vue family bucket: Core + Vue Router + VUex

Vue installation mode

  • Introduced the CDN

    The development environment

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    Copy the code

    The production environment

    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    Copy the code
  • Download and Import

  • NPM installation management

    npm install vue
    Copy the code

At the beginning of the vue experience

  • Hello Vue.js

<! DOCTYPEhtml>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="Width = device - width, initial - scale = 1.0">
    <title>Document</title>
  </head>
  <body>

    <div id="app">
      <! -- Responsive -->
      <h2>{{ message }}</h2>
      <h3>{{ name }}</h3>
    </div>

    <! -- There is no VUE to manage -->
    <div>
      {{ message }}
    </div>

    <script src=".. /js/vue.js"></script>

    <script>
      const app = new Vue({
        el: '#app'.// Used to mount the element to be managed
        // Define data
        data: {
          message: 'Hello, Vue! '.name: 'xx'}});</script>
  </body>
</html>
Copy the code
  • Vue list display

<! DOCTYPEhtml>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="Width = device - width, initial - scale = 1.0">
    <title>Document</title>
  </head>
  <body>

    <div id="app">
      {{ movies }}

      <ul>
        <li v-for="item in movies">{{ item }}</li>
      </ul>
    </div>

    <script src=".. /js/vue.js"></script>

    <script>
      const app = new Vue({
        el: '#app'.data: {
          message: 'Hello Vue'.movies: ['movie1'.'movie2'.'movie3']}});</script>
  </body>
</html>
Copy the code
  • Case study: counters

<! DOCTYPEhtml>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="Width = device - width, initial - scale = 1.0">
    <title>Document</title>
  </head>
  <body>

    <div id="app">
      <h2>current counter: {{ counter }}</h2>
      <button @click="add">+</button>
      <button @click="sub">-</button>
    </div>

    <script src=".. /js/vue.js"></script>

    <script>
      const app = new Vue({
        el: '#app'.data: {
          counter: 0
        },
        methods: {
          add() {
            this.counter++;
          },
          sub() {
            this.counter--; }}})</script>
  </body>
</html>
Copy the code

The vue MVVM

The vue MVVM

View: DOM

Model: JS object

ViewModel: Vue instance DOM Listeners, Data Bindings