vue.js basis __ mixins options

mixins option is mainly used in new demand;

Without changing the existing methods, the use of mixins mixed option;

- Click to add 1, for example, is divided into two kinds of local and global

- Set the updated method and then mixed with options

- updated method is set in the local, global, and the raw process

- execution priority order is updated global execution, and executes the updated local methods, the last updated native method execution

Code examples are as follows:

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>mixins option</title>
<script src="../assets/js/vue.js"></script>
</head>

<body>
<h1>mixins option</h1>
<hr>
<div id="app">
{{on one}}
<p><button @click="add">add</button></p>
</div>

<script>

was addConsole = {
updated() {
console.log ( `data is changed to` + this.num);
}
}

Vue.mixin ({
updated () {
console.log ( 'I am a globally updated');
 
}
})

was app = new Vue ({
the '#app'
data: {
a: 1
},
methods: {
add() {
this.num++
}
},
updated () {
console.log ( 'I am a native updated');
},
mixins: [addConsole]
})
</script>
</body>

</html>

 

Guess you like

Origin www.cnblogs.com/sunyang-001/p/11104910.html