1. Vue OverviewVue official websiteEnglish official website: https://vuejs.org/ Chinese official website: https://cn.vuejs.org/ MVVM architectural pattern
MVVM consists of three parts: M: Under the MVVM architecture, there is no direct connection between View and Model. Instead, they interact through ViewModel. The interaction between Model and ViewModel is two-way, so changes in View data will be synchronized to the Model, and changes in Model data will be immediately reflected in the View. ViewModel connects the View layer and the Model layer through two-way data binding, and the synchronization between View and Model is completely automatic and does not require human intervention. Therefore, developers only need to focus on business logic and do not need to manually operate DOM or worry about data status synchronization issues. Complex data status maintenance is completely managed by MVVM.
Introduction to Vue
2. Getting started with Vue
Pay attention to the difference between js expressions and js codes (statements) 1. Expression: An expression produces a value and can be placed anywhere a value is required (1). (2). a+b (3). demo(1) //Function call expression (4). x === y ? 'a' : 'b' //Ternary expression 2, js code (statement) (1). if(){} (2). for(){}
<!-- Prepare a container --> <div id="demo"> <h1>Hello, {{name.toUpperCase()}}, {{address}}</h1> </div> <script type="text/javascript" > Vue.config.productionTip = false //Prevent Vue from generating production tips at startup. //Create a Vue instance new Vue({ el:'#demo', //el is used to specify which container the current Vue instance serves. The value is usually a CSS selector string. data:{ //data is used to store data. The data is used by the container specified by el. We will temporarily write the value into an object. name:'bilibili', address:'Shanghai' } }) </script> 3. Template SyntaxThere are two main categories of Vue template syntax: 1. Interpolation syntax:
2. Command syntax:
<!-- Prepare a container --> <div id="root"> <h1>Interpolation Syntax</h1> <h3>Hello, {{name}}</h3> <hr/> <h1>Command Syntax</h1> <a v-bind:href="address.url.toUpperCase()" x="hello">Click me to {{address.name}}1</a> <a :href="address.url" x="hello">Click me to go to {{address.name}}2</a> </div> <script type="text/javascript"> Vue.config.productionTip = false //Prevent Vue from generating production tips at startup. new Vue({ el:'#root', data:{ name:'月见', // Can be set to a multi-level structure address:{ name:'Baidu', url:'http://www.baidu.com', } } }) </script> 4. Data BindingThere are two ways of data binding in Vue: 1. One-way binding (v-bind) 2. Two-way binding (v-model) Remark:
<div id="root"> <!-- Normal writing --> One-way data binding: <input type="text" v-bind:value="name"><br/> Two-way data binding: <input type="text" v-model:value="name"><br/> <!-- Abbreviation --> One-way data binding: <input type="text" :value="name"><br/> Two-way data binding: <input type="text" v-model="name"><br/> <!-- The following code is wrong, because v-model can only be applied to form elements (input elements)--> <h2 v-model:x="name">Hello</h2> </div> <script type="text/javascript"> Vue.config.productionTip = false //Prevent Vue from generating production tips at startup. new Vue({ el:'#root', data:{ name:'bilibili' } }) </script> 5. Two ways to write el and data1. There are two ways to write el: new
2. There are two ways to write data
3. An important principle:Functions managed by Vue must Don't write arrow functions. Once you write an arrow function, this is no longer a Vue instance, but a window. <div id="root"> <h1>Hello, {{name}}</h1> </div> <script type="text/javascript"> Vue.config.productionTip = false //Prevent Vue from generating production tips at startup. //Two ways of writing el----------- const v = new Vue({ //el:'#root', //The first way to write data:{ name:'bilibili' } }) console.log(v) v.$mount('#root') //The second way of writing // Example: setTimeout(() => { v.$mount('#root') },1000); //Timer: The page will display the Vue effect after 1 second// --------------------- //Two ways to write data new Vue({ el:'#root', //The first way to write data: object style /* data:{ name:'bilibili' } */ //The second way to write data: functional style // Write data as a function, and this function must return an object. Functional writing is generally used for components and frameworks // Note: This function is not called by itself, but by Vue data(){ // console.log('@@@',this) //This is the Vue instance object (when data is a normal function, otherwise this refers to window) return { name:'bilibili' } } }) </script> SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: A detailed summary of HTML tag nesting rules suitable for beginners
>>: HTML adaptive table method
1. What is mycat A completely open source large d...
Usually, there are two options when we develop Li...
Table of contents Preface 1.v-show 2.v-if 3. The ...
This article example shares the specific code of ...
Problem Description There is a type of query call...
Table of contents Introduction Download and insta...
1. Why set maxPostSize? The tomcat container has ...
background go-fastdfs is a distributed file syste...
This article example shares the specific code of ...
Change the default style of select, usually throug...
You can call it directly in the Linux shell envir...
Background Threads •Master Thread The core backgr...
Many people have encountered this error when star...
The so-called container actually creates a readab...
1. Download the alpine image [root@docker43 ~]# d...