vue form表單綁定事件與方法


    使用v-on綁定事件  
        <button @click="hello">Hello</button><br />  
        <button @click="say('I love you')">say</button><br />  
        訪問原生事件  
        <button @click="do('Nihao',$event)">do</button><br />  
          
          
        事件修飾符<br />  
        <form v-on:submit.prevent="onSubmit" action="http://www.baidu.com">  
            <a @click.stop="doThis">阻止單擊事件冒泡</a>  
            <input type="submit" value="提交事件不再負載頁面" />  
            <input v-on:keyup.enter="submit" type="submit" value="只有在keyup等於enter才提交">  
        </form>  
        <br /><br />  
        表單控件綁定:  
        使用V-model進行雙向綁定,處理一些極端的需求,如下:  
        <span>Message is:{{message}}</span><br />  
        <input type="text" v-model="message" placeholder="Edit me" /><br /><br /><br />  
        單個多選框:邏輯值  
        <input type="checkbox" id="checkbox" v-model="checked" value="游泳"/>游泳?  
        <label for="checkbox">{{checked}}</label>  
        <br /><br /><br /><br />  
        綁定到數組:不是邏輯值,是value的值  
        <input type="checkbox" value="A" v-model="model" id="A" />  
        <label for="A">A</label>  
        <input type="checkbox" value="B" v-model="model" id="B" />  
        <label for="B">B</label>  
        <input type="checkbox" value="C" v-model="model" id="C" />  
        <label for="C">C</label><br />  
        <span>selcted:{{model | json}}</span>  
          
        單選框:<br />  
        <input type="radio" value="男" v-model="sex" /><input type="radio" value="女" v-model="sex" /><br /><span>{{sex}}</span>  
          
        下拉框:<br />  
        <select v-model="selected" multiple>  
          <option selected>A</option>  
          <option>B</option>  
          <option>C</option>  
        </select>  
        <br>  
        <span>Selected: {{ selected | json }}</span>  
          
          
        <!-- 在 "change" 而不是 "input" 事件中更新 -->  
        <input v-model="msg" lazy><span>{{msg}}</span><br /><br />  
        <input v-model="age" number><span>{{age}}</span>  
    var vm=new Vue({  
        el:'#app',  
        data:{  
            text:'Hello',  
            model:[]  
        },  
        methods:{  
            hello:function(){  
                alert(this.text+" Vue.js");  
            },  
            say:function(text){  
                alert('say'+text);  
            },  
            do:function(text,event){  
                alert(text);  
                event.preventDefault();  
            }  
        }  
    });  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM