Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Vue .js introduction


May 29, 2021 Article blog



Vue .js is a front-end library for developing web interfaces, with accompanying peripheral tools, and this article asks you about Vue's .js

Responsive programming

Show data, object examples:

var object = {
  message: 'Hello World!'
}

A special template

<div id="example">
  {{ message }}
</div>

We can assemble them via Vue

new Vue({
  el: '#example',
  data: object
})

Vue has changed the object object to a responsive object, and the rendered HTML updates synchronously when you modify the message value.

Vue calculates the property

var example = new Vue({
  data: {
    a: 1
  },
  computed: {
    b: function () {
      return this.a + 1
    }
  }
})
 
// example 实例会同时代理 a 和 b 这两个属性.
example.a // -> 1
example.b // -> 2
example.a++
example.b // -> 3

At this point, the calculated property b tracks a as a dependency, and a changes and b changes together.

Let's look at another example of a counter:

 Vue .js introduction1

The code is as follows:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>vue-w3cschool(编程狮)</title>
    <script src="vue/Vue.demo/vue.js"></script>
</head>
<body>
<div id="app">
    <p>计数器:{{counter}}</p>
    <button @click="sub">-</button>
    <button @click="add">+</button>
</div>

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

Here's what the editor brings you about Vue .js.