Vue 表单
2018-06-24 01:04:41来源:未知 阅读 ()
1、v-model
v-model不再关心初始化的value值。
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>购物车示例</title>
</head>
<body>
<div id="app" v-cloak>
<input type="text" v-model="message" value="122" placeholder="请输入" />
<p>输入的文本内容是:{{message}}</p>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
message: ''
}
})
</script>
</body>
</html>
效果:
2、单选
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Vue</title>
</head>
<body>
<div id="app">
<input type="radio" v-model="picked" value="html" id="html" />
<label for="html">HTML</label>
<br />
<input type="radio" v-model="picked" value="js" id="js" />
<label for="js">HTML</label>
<br />
<input type="radio" v-model="picked" value="css" id="css" />
<label for="css">HTML</label>
<br />
<p>选择项为:{{picked}}</p>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
picked: 'js'
}
})
</script>
</body>
</html>
3、复选框
(1)单独使用时
v-model绑定布尔值
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Vue</title>
</head>
<body>
<div id="app">
<input type="checkbox" v-model="checked"/>js
<p>选择项为:{{checked}}</p>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
checked: false
}
})
</script>
</body>
</html>
(2)组合使用
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Vue</title>
</head>
<body>
<div id="app">
<input type="checkbox" v-model="checked" value="html" id="html" />html
<lable for='html'>html</lable>
<br />
<input type="checkbox" v-model="checked" value="js" id="js" />js
<lable for='js'>js</lable>
<br />
<input type="checkbox" v-model="checked" value="css" id="css" />css
<lable for='css'>css</lable>
<br />
<p>选择项为:{{checked}}</p>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
checked: []
}
})
</script>
</body>
</html>
4、下拉列表
(1)单选下拉列表
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Vue</title>
</head>
<body>
<div id="app">
<select v-model="selected">
<option value="0">html</option>
<option value="1">js</option>
<option value="2">css</option>
</select>
<br />
<p>选择项为:{{selected}}</p>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
selected: 0
}
})
</script>
</body>
</html>
(2)多选下拉列表
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Vue</title>
</head>
<body>
<div id="app">
<select v-model="selected" multiple="multiple">
<option value="0">html</option>
<option value="1">js</option>
<option value="2">css</option>
</select>
<br />
<p>选择项为:{{selected}}</p>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
selected: []
}
})
</script>
</body>
</html>
5、修饰符
(1)lazy
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Vue</title>
</head>
<body>
<div id="app">
<!--在change中同步-->
<input type="text" v-model.lazy="message" />
<br />
<p>{{message}}</p>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
message: '',
}
})
</script>
</body>
</html>
(2)number
输入转为number类型
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Vue</title>
</head>
<body>
<div id="app">
<!--在change中同步-->
<input type="number" v-model.number="message" />
<br />
<p>{{ typeof message}}</p>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
message: 123,
}
})
</script>
</body>
</html>
(3)trim
去掉输入框的首尾空格
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<title>Vue</title>
</head>
<body>
<div id="app">
<!--在change中同步-->
<input type="text" v-model.trim="message" />
<br />
<p>{{message}}</p>
</div>
<script src="https://cdn.bootcss.com/vue/2.5.9/vue.min.js"></script>
<script type="text/javascript">
new Vue({
el: "#app",
data: {
message: ' 5555 66 ',
}
})
</script>
</body>
</html>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- js防止表单重复提交实现代码 2020-03-29
- js的验证表单 2020-03-18
- vue.js开发环境搭建教程 2020-03-16
- jQuery异步提交表单的两种方式 2020-03-12
- Vue input控件通过value绑定动态属性及修饰符的方法 2020-03-05
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash