vue learn front-end framework

Vue.js description:

Vue.js is a progressive frame data driver web interface construct. Vue.js goal is to achieve as far as possible through a simple API response data binding component, and combinations of views. It is not only easy to use but also easy to integrate with existing third-party libraries or projects.

 

MVVM pattern

  MVVM is a Model-View-ViewModel shorthand. It is essentially an improved version Mvc. mvvm is to state which of view and behavior of abstraction, let's views ui and business logic separate

  mvvm mvc mode and patterns, the main purpose is to separate the view and model

  vue.js is a javascript library provides two-way data binding mvvm style, focusing on the view layer. At its heart is mvvm in vm. That is viewmodel. viewmodel responsible for the connection and view model, and ensure a consistent view of data, this lightweight architecture allows front-end development more efficient and convenient.

 

 

Interpolation expression

 

Data Binding The most common form is the use of "Mustache" syntax (curly brackets) Text Interpolation:

  1. <span>Message: {{ msg }}</span>

Mustache tag will be replaced on the corresponding data object msgattribute. Whenever the data objects bound msgproperty is changed, the content will be updated at the interpolation.

By using the v-once instruction, you can perform a one-time interpolation, when the data changes, the content is not updated at the interpolation. But please pay attention this will affect all the data bindings on this node:

  1. <span v-once>This will never change: {{ msg }}</span>

These expressions can be resolved in a data example of an action Vue javascript. There is a limit, each binding can only contain a single expression, so the following example will not take effect.

  <! - This is a statement, not an expression ->

  There are a = {{1}}

  <! --- flow control will not take effect, ternary expression ->

   {{if(ok){return message} }}

v-on

Dom can monitor events with v-on instruction, and run some javascript code when triggered

v-on:click

<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="js/vue.min.js"></script>
</head>
<body>
<div id="app">
{{message}}
<button v-on:click="fun1()">vue的onclick</button>

</div>

</body>
<script>
new Vue({
el:"#app",
data:{
message:"hello vue!"
},
methods:{
fun1:function () {
alert("hello");

}
}
});
</script>
</html>

 

 

 

vue of the v-on mouse move events and stop events

<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style >
        #div{
            background-color: red ;
            width: 200px;
            height: 200px;
        }
    </style>
    <script src="js/vue.min.js"></script>

</head>
<body>
    <div id="app">
        // @ name of the event is the v-on: shorthand for the event. 
        <div @ mouseOver = " fun1 " div = " div " > 
             <TextArea V-ON: mouseOver = " fun2 ($ Event) " > This is a text field </ TextArea> 
        </ div> 
        <div the onmouseover = " divmouseover ( ) " ID = " div " > 
            <TextArea the onmouseover = " textareamouseover () " > this is a file field </ TextArea> 
        </ div> 
    </ div> 
</ body> 
    <Script>
          
          
              EL: " #app " , 
              Methods: { 
                  fun1: function () { 
                      Alert ( " hover over div " ); 
                  }, 
                  fun2: function ( Event ) { 
                      Alert ( " hover over TextArea " );
                       Event .stopPropagation (); 
                  } 
              } 
          }) 
        // conventional manner js 
        function divmouseover () { 
            Alert ( " the mouse to move to the div " );
        } 

        Function textareamouseover () { 
             Alert ( " the mouse to move to the textera " );
              Event .stopPropagation (); 
        }
     </ Script> 
</ HTML>
View Code

 

 

vue in the event modifier

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>v-on:事件修饰符</title>
    <style>
        #div{
            background-color: red;
            height: 300px;
            width: 300px;
        }
    </style>
    <script src="js/vue.min.js"></script>
</head>
<body>
        <div id="app">
            <form  @subimit.prevent action="http://www.itheima.com" method="post" >
                <input type="submit" value="提交">
            </form>
            <hr>
            <form action="http://www.itheima.com" method="post" onsubmit="checkForm()">
                <input type="submit" value="提交">
            </form>
            <div @mouseover="fun1" The above mentioned id = " div " > 
                <@ mouseover.stop the TextArea = " fun2 ($ Event) " > This is a text field </ the TextArea> 
            </ div> 
        </ div> 
</ body> 
    <Script> // Vue new new VUE ({ 
            EL: " #app " , 
            Methods: { 
                fun1: function () { 
                    Alert ( " hover over div " ); 
                }, 
                fun2:function (event) {
                    alert("
        
        Hover over TextArea " ); 
                } 
            } 

        }); 
        // traditional paradigm js 
          function checkForm () { 
              Alert ( . 1 ;)
               // form validation must have a clear return a boolean value
               // in the application verification method The method name must be added to return 
              return  to false ; 
          }
     </ Script> 
</ HTML>
View Code

Note: prevent form submission

 

v-text and v-html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="js/vue.min.js"></script>
    <title>v-text和v-html</title>
</head>
<body>
<div id="app">
        <div v-text="message"></div>
        <div v-html="message"></div>
    <div id="div1"></div>
    <div id="div2"></div>
</div>

</body>
<script>//view modelnew Vue({
        el:"#app",
        data:{
            message:"<h1>hello</h1>"
        }
    })//传统js的innertext和innerHtml
    window.onload=function () {
        document.getElementById("#div1").innerHTML="<h1>Hello</h1>";
        document.getElementById("#div2"") .innerText =
    
    
    <h1>hello</h1>";

    }
</script>

</html>
View Code

 

Guess you like

Origin www.cnblogs.com/wq-9/p/11617955.html