vue事件的綁定


<!doctype html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>事件綁定</title>
    <script src="js/vue.js"></script>
 </head>
 <body>
  <div id="container">
        <p>{{msg}}</p>
        <button v-on:click="handleClick">Click Me</button>
        <button @click="handleClick">Click Me</button>
        <h5>select</h5>
        <select v-on:change="handleChange">
            <option value="red">紅色</option>
            <option value="green">綠色</option>
            <option value="pink">粉色</option>
        </select>
        <h5>表單提交</h5>
        <form v-on:submit.prevent="handleSubmit">
            <input type="checkbox" :checked="false" v-on:click="handleDisabled"/>
            是否同意本站協議
            <br>
            <button :disabled="isDisabled">提交</button>
        </form>
    </div>
    <script>
        new Vue({
            el:"#container",
            data:{
                msg:"Hello VueJs",
                isDisabled:false
            },
            //methods對象
            methods:{
                //通過methods來定義需要的方法
                handleClick:function(){
                    console.log("btn is clicked");
                },
                handleChange:function(event){
                    console.log("選擇了某選項"+event.target.value);
                },
                handleSubmit:function(){
                    console.log("觸發事件");
                },
                handleDisabled:function(e){
                    if(event.target.checked==true){
                        this.isDisabled =  true;
                    }
                    else{
                        this.isDisabled =  false;
                    }
                }
            }
        })
    </script>
 </body>
</html>

 


免責聲明!

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



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