v-on

作用:为html标签绑定事件添加事件监听
语法:
v-on:事件名="方法名"
简写为  @事件名="…"

例:

            <button type="button" v-on:click="search">查询</button>
            <button type="button" @click="clear">清空</button>
 
search clear方法在脚本methods中编写,mothods和data()是对等的要用逗号隔开
 
        methods: {
            search(){
                //将搜索条件, 输出到控制台
                console.log(this.searchForm);//console.log() 输出到控制台
            },//methods各方法之间逗号隔开,
            clear(){
                //清空表单项数据
                this.searchForm = {name:'', gender:'', job:''}//赋值空值或者其他值前要有属性名加冒号:
            }
        },
posted @ 2025-07-05 18:50  休玛  阅读(5)  评论(0)    收藏  举报