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();
}
}
});
vue form表单绑定事件与方法的更多相关文章
- 20181019 记录 window.setTimeout('dofunction()',2000); - layui form 表单提交 事件 - F11全屏 事件 window.onresize
1 延时事件 window.setTimeout('dofunction()',2000); 函数外面要有引号 如果没有引号 就不能延时执行 应该是内容进行eval,所以外层不是传递字符串的话,外层函 ...
- form表单submit事件
form表单submit事件同时会触发form表单中button按钮的click事件 <!DOCTYPE html> <html> <head> <meta ...
- vue -- v-model 表单绑定
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 使用js提交form表单的两种方法
提交form表单的时候瑶族一些简单的验证,验证完后才能提交,避免无效提交. 1.当输入用户名和密码为空的时候,需要判断.这时候就用到了校验用户名和密码,这个需要在前端页面写:有两种方法,一种是用sub ...
- form表单重置、清空方法记录
myform 是form的id属性值 1.调用reset()方法 function fomrReset() { document.getElementById("myform"). ...
- vue form表单上传文件
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js">< ...
- Ajax提交Form表单的一种方法
待提交的表单 <form id="updatePublicKey" enctype="multipart/form-data"> <div c ...
- Django 构建模板form表单的两种方法
通常情况下,我们想构建一张表单时会在模板文件login.html中写入 <form action="/your-name/" method="post"& ...
- SharePoint 使用脚本为表单绑定事件
在SharePoint的使用过程中,我们经常需要为表单页面做一些特殊处理,比如说新建页面的时候有多选项的字段,但是只能选择指定数量的选项,尤其在新闻列表或者调查列表等特殊场景中,广泛使用. 下面,我们 ...
随机推荐
- C#对DataTable里数据筛选排序的方法
在日常开发过程中,有一个DataTable集合,里面有很多字段,现在要求针对某一列进行排序,如果该列为数字的话,进行ASC即可实现,但是该字段类型为string,此时排序就有点不正确了 protect ...
- LeetCode: Best Time to Buy and Sell Stock 解题报告
Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of a gi ...
- 九章面试题:Find first K frequency numbers 解题报告
Find first K frequency numbers /* * Input: int[] A = {1, 1, 2, 3, 4, 5, 2}; k = 3 * return the highe ...
- 如何在linux下查看目录的剩余空间大小
df命令是linux系统以磁盘分区为单位查看文件系统,可以加上参数查看磁盘剩余空间信息,命令格式: df -hl 显示格式为: 文件系统 容量 已用 可用 已用% 挂载点 Filesystem Siz ...
- 综合出现NSScanner: nil string argument libc++abi.dylib: terminat错误的解决方案
在开发中出现了这个错误,断点查找很久,没找到问题所在的代码,google下,发现了下面这几点会产生这个错误: 首先,顾名思义,错误原因是我们在调用某个方法的时候,传入了一个空字符串(注意区别于字符串内 ...
- python 下载虾米音乐
#!/usr/bin/env python2 # coding:utf-8 import urllib import re import sys import urllib2 # xml => ...
- mac上校验文件的 md5 sha-1
文件校验 mac md5 sha-1html, body {overflow-x: initial !important;}.CodeMirror { height: auto; } .CodeMir ...
- <要做股市赢家:杨百万>读书笔记
书在这里 和这里: 要注意的是,并不是政府每出台一个政策股价就要变.如果听到各种消息,市场却没有反应,就不要去做这个聪明人.有消息后应该密切关注市场反应,看成交量.价格的变化等等,再作决定.总之,关键 ...
- ubuntu 14.04 gitlab 的搭建
经过两天的尝试,gitlab 终于在 ubuntu14.04 上面搭建起来. 一.安装相关软件. // 执行如下命令: sudo apt-get install vim git curl openss ...
- 计算机名、主机名、用户账户名与NetBIOS名有什么区别
1.计算机名:右击“我的电脑”,选择“属性”,在“系统属性”对话框的“计算机名”选项卡里,可以设置计算机名.计算机名是对域(或工作组)中的计算机的标识,如果你的计算机名设置为“至清水”,则在网上邻居里 ...