-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ant design vue #310
Comments
Form期望在form中的data通过validation后才同步到其他组件进行展示。 不是 而是 Steps
form表单的使用form表单之获取表单的数据 原文链接:https://blog.csdn.net/weixin_44051815/java/article/details/88305722 创建表单 <template>
<a-form @submit="handleOk" :form="form">
// :form="form" 必须优先注册
<!-- 客户姓名 -->
<a-form-item
:labelCol="labelCol" // 排列样式
:wrapperCol="wrapperCol"
label='客户姓名:'
>
<a-input
v-decorator="[
'name', // 给表单赋值或拉取表单时,该input对应的key
{rules: [{ required: true, message: '请输入客户名称!' }]}
]"
placeholder="请输入客户名称"/>
</a-form-item>
</a-form>
</template>
export default {
data() {
return {
form: this.$form.createForm(this), // 只有这样注册后,才能通过表单拉取数据
}
}
}
拉取表单数据的方法 this.form.validateFields((err, values) => {
if (err) {
// 这里做逻辑处理
console.log(values) // { name: '' }
}
} 清空表单的方法 给表单赋值 this.form.setFieldsValue({
name: '设置值'
}) 给表单中添加自定义校验 <a-form-item
v-bind="formItemLayout"
label="E-mail"
>
<a-input
v-decorator="[
'email',
{
rules: [{
type: 'email', message: 'The input is not valid E-mail!',
}, {
required: true, message: 'Please input your E-mail!',
}]
}
]"
/>
</a-form-item> 推荐使用下面的方式做自定义校验,当输入框失去焦点后再去校验是否正确 <a-form-item
:labelCol="labelCol"
:wrapperCol="wrapperCol"
label='手机:'
>
<a-input
type="number"
v-decorator="[
'phone',
{
rules: [
{ required: false, message: '请输入手机号码!' },]
},
]"
@blur="validatePhoneBlur"
placeholder='请输入手机号码' />
</a-form-item>
// 校验事件
validatePhoneBlur(e) {
const validatePhoneReg = /^1\d{10}$/
if (e.target.value && !validatePhoneReg.test(e.target.value)) {
const arr = [{
message: '您输入的手机格式不正确!',
field: 'phone',
}]
this.form.setFields({ phone: { value: e.target.value, errors: arr } })
}
}, |
momentimport moment from "moment";
import "moment/locale/ja"; // without this line it didn't work
moment.locale("ja"); <a-time-picker
style="margin-left: 10px;"
v-decorator="[
'startTime',
{ initialValue: moment('08:00', 'HH:mm') },
]"
format="HH:mm"
/>
<script>
import moment from "moment";
export default {
methods: {
moment, moment取值由于用ant design日期组件取得的值是moment类型,而往数据库中保存需要的是字符串类型
|
全量导入
组件数轻松上20, 我已经没有耐心使用按需导入了。
暴力
import Antd from "ant-design-vue"
提示Antd找不到~, 解决办法: 把babel.config.js中的下面这段删除,然后~~
table 中的boolean字段不能显示值
弄个customRender.
checkbox 设置初值 要 指定 valuePropName 为 checked
You cannot set a form field before rendering a field associated with the value.
出现这个错误的原因:
<a-form-item>
标签!this.form.setFieldsValue({ fieldName1: 0, fieldName2: [1, 2] });
The text was updated successfully, but these errors were encountered: