ant design vue input change_vue 表单
文档:https://cn.vuejs.org/v2/guide/forms.html#ad
基本用法
使用vue脚手架
- 安装Nodejs
- 安装yarn:https://yarn.bootcss.com/docs/install/#windows-stable
- 安装 Vue CLI
npm install -g @vue/cli
# OR
yarn global add @vue/cli
- 创建项目:
vue create .
- yes 后回车
安装完毕,接下来可以运行 vue代码了,运行 yarn serve
实时预览
input
//尝试着对message进行修改:
<input v-model="message" placeholder="edit me">
<p>Message is: {{ message }}</p>export default {name: 'App',data(){return {message: 'hi'}}
}
改内存的东西页面会跟着改变,这就是双向绑定
textarea
<textarea v-model="message" placeholder="edit me"></textarea>
<p>Message is: {{ message }}</p>
checkbox
// 单个绑定布尔值
<label><input type="checkbox" v-model="x"><span>x: {{x}}</span>
</label>// 多个绑定数组
// 单选框用radio,最好加上name,表示是一组的
<div id="app">爱好:{{x}}<label><input name="want" type="checkbox" v-model="x" :value="1"><span>抽烟</span></label><label><input name="want" type="checkbox" v-model="x" :value="2"><span>喝酒</span></label><label><input name="want" type="checkbox" v-model="x" :value="3"><span>泡妞</span></label>
</div>export default {name: 'App',data(){return {x: []}}
}
select
<div id="app">想要:{{x}}<hr /><select v-model="x"><option v-for="item in array" :value="item.value" :key="item.value">{{item.text}}</option></select>
</div>export default {name: 'App',data(){return {array: [{text: '抽烟', value: 1},{text: '喝酒', value: 2},{text: '泡妞', value: 3}],x: ""}}
}
// 多选用 multiple,shift+点击,ctrl+点击
form
<div id="app">登录<form @submit.prevent="onSubmit" action=""><label for=""><span>用户名</span><input type="text" v-model="user.username" /></label><label for=""><span>密码</span><input type="password" v-model="user.password"/></label><button type="submit">登录</button></form>
</div>export default {name: 'App',data(){return {user:{username: '',password: ''},x: ""}},methods: {onSubmit(){console.log(this.user)}}
}
想要回车提交必须要有form和button
修饰符
.lazy
<input type="text" v-model.lazy="user.username" />
// 不那么快变化
默认使用 input 事件,input时间包括键盘、鼠标、任何输入设备的输入
.number
只要数字
<input type="text" v-model.number="user.username" />
// 只要数字的名字,如果数据类型是number,那么最好使用.number修饰符
.trim
去掉多余空格
<input type="text" v-model.trim="user.username" />
v-model
等价写法
文档:https://cn.vuejs.org/v2/guide/components-custom-events.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9A%84-v-model
<input type="text" v-model.trim="user.username" />
// 相当于
<input type="text" :value="user.username" @input="user.username = $event.target.value"/>
// 如果是 .sync 的话就直接等于 $event
v-model
等价写法就是绑定:value
等于一个东西,然后@input
让这个东西等于 $event.target.value
自定义input
<template><div class="red wrapper"><input :value="value" @input="onInput" /></div>
</template><script>
export default {name: 'MyInput',props: {value: {type: String}},methods: {onInput(e){const value = e.target.valuethis.$emit('input', value)}}
}
// 要么使用 :value 与 @input 组合,要么使用 v-model
使用 Ant-Design-Vue
安装与引入使用
npm install ant-design-vue --save
// 或者
yarn add ant-design-vue// 全局引用
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
Vue.use(Antd);// 局部引用
import { Button, message } from 'ant-design-vue';
Vue.use(Button);
Vue.prototype.$message = message;
登录框
<template><a-formid="components-form-demo-normal-login":form="form"class="login-form"@submit="handleSubmit"><a-form-item><a-inputv-decorator="['userName',{ rules: [{ required: true, message: 'Please input your username!' }] },]"placeholder="Username"><a-icon slot="prefix" type="user" style="color: rgba(0,0,0,.25)" /></a-input></a-form-item><a-form-item><a-inputv-decorator="['password',{ rules: [{ required: true, message: 'Please input your Password!' }] },]"type="password"placeholder="Password"><a-icon slot="prefix" type="lock" style="color: rgba(0,0,0,.25)" /></a-input></a-form-item><a-form-item><a-checkboxv-decorator="['remember',{valuePropName: 'checked',initialValue: true,},]">Remember me</a-checkbox><a class="login-form-forgot" href="">Forgot password</a><a-button type="primary" html-type="submit" class="login-form-button">Log in</a-button>Or<a href="">register now!</a></a-form-item></a-form>
</template><script>
export default {beforeCreate() {this.form = this.$form.createForm(this, { name: 'normal_login' });},methods: {handleSubmit(e) {e.preventDefault();this.form.validateFields((err, values) => {if (!err) {console.log('Received values of form: ', values);}});},},
};
</script>
<style>
#components-form-demo-normal-login .login-form {max-width: 300px;
}
#components-form-demo-normal-login .login-form-forgot {float: right;
}
#components-form-demo-normal-login .login-form-button {width: 100%;
}
</style>
校验规则
校验示例:
v-decorator="['password',{ rules: [{ required: true, message: '你丫没填密码!'},{ min: 8, message: '密码最少8个字符,'}, {pattern: /[a-zA-z]/, message: '必须包含至少一个字母'}] }
]"
具体用法看文档:https://antdv.com/docs/vue/introduce-cn/
ant design vue input change_vue 表单相关推荐
- ant design vue input change_vue中关于$emit用法的笔记
在 index.html 中引用了 input.vue 中的 <g-input>,如下 1.index.html <div id="app"><g-i ...
- ant design vue input change_ElementUI 不维护了?供我们选择的 Vue 组件库还有很多!
1 ElementUI 近况 根据我最近的观察,得知一些关于 ElementUI 维护人员都退去的消息,这意味着什么? 这意味着后期 ElementUI 将无人维护,就算 Vue3.0 正式版出来 E ...
- ant design vue input change_Ant-design-vue项目实现动态路由
vue项目实现动态路由的方式大体可分为两种: 1.前端这边把路由写好,登录的时候根据用户的角色权限来动态展示路由,(前端控制路由) 2.后台传来当前用户对应权限的路由表,前端通过调接口拿到路由信息后处 ...
- Ant Design Vue Input 输入框设置只读
<a-input v-model="A" placeholder="请输入"/> 只读 readonly 需要写成 readOnly <a-i ...
- Vue 2.x折腾记 - (16) 基于Ant Design Vue 封装一个配置式的表单搜索组件
前言 这次的后台管理系统项目选型用了Vue来作为主技术栈: 因为前段时间用过React来写过项目(用了antd),感觉棒棒的. 所以这次就排除了Element UI,而采用了Ant Design Vu ...
- Ant Design Vue 如何获form表单里数据 并给 v-decorator绑定的数据重新赋值
最近在用ant design vue 做项目 遇到了 一下坑 比如 v-decorator 可以做数据 绑定 与v-model 不同的是 给 form 表单赋值 v-model 的值是 双向绑定的 如 ...
- vue使用Ant design的input输入框,去掉边框和获取焦点时的边框
vue使用Ant design的input输入框,去掉边框和获取焦点时的边框 /* 取消 多行文本框 伸缩效果 resize: none; */ /* 取消 多行文本框 边框 border: none ...
- ant design vue table 高度自适应_Vue组件库大评测 Element, iView, HeyUI, Ant Design Vue
今天偶然的机会想了解下其他Vue相关的组件库,网上刚好有文章,顺便自己做一下笔记,算是资源整理吧 .好了,话不多说,直接开始: 组件库的选择对于前端开发有者至关重要的影响,而组件的丰富性以及健壮性是我 ...
- 2019年 Vue 组件库大评测 Element, iView, HeyUI, Ant Design Vue
2018年我写的Vue组件库对比文档: https://juejin.im/post/5a9628415188257a7b5ac678 一年的时间,每一个组件库都有了更多的发展,Ant Design ...
最新文章
- apn java_android设置移动联通电信wap接入点
- 阿里开源新一代人机对话模型 ESIM,曾创下人机对话准确率新纪录
- Crawler之Scrapy:数据挖掘必备的scrapy框架之最完整爬取网页内容攻略
- C语言从已排序的链表中删除重复项(附完整源码)
- 卡尔曼滤波(Calman Filter)基本原理
- 【CodeForces - 471B】MUH and Important Things (模拟,细节)
- 记一次有意思的种树比赛
- 电脑安装系统后出现no bootable device_炉石传说:用电脑领取安卓和iOS专属卡包你能信?亲测有效!...
- c语言微信挑一挑编程,100行python代码实现微信跳一跳辅助程序
- Shell中$X的含义
- vscode集成linux的git,vscode中内置集成终端显示为git(bash.exe)
- arduino声音传感器与二极管_Arduino声音传感器
- eXeScope 注册机制破解
- 《STM32从零开始学习历程》——SPI读取FLASH ID
- 【笔记】一些Attention 方面的网络
- java 多线程,android 移动开发,日语学习,各项新闻RSS吐血分享
- no moudle named sklearn-impute
- linux下下载fnl数据,如何下载fnl
- win10多用户同时远程桌面登陆(允许多个RDP会话)-支持win10最新1909版2004版
- 邮箱个性签名html模板,邮件个性签名大全_邮件的经典个性签名模板