使用 vue-cli 安装 Ant Design Vue 的 Form 组件,发现不能用,组件样式不显示。
此处省略了安装和初始化的步骤,需要的点击上方链接,直接在 Ant Design 官网查看教程。
在 main.js 中全局引入:
import { Form, Input, Select } from 'ant-design-vue';
因为我进行了 按需加载组件代码 的配置,所以只需要上面一行就可以。
引用官网的一个基础示例:
<template>
<a-form :form="form" @submit="handleSubmit">
<a-form-item label="Note" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
<a-input
v-decorator="['note', { rules: [{ required: true, message: 'Please input your note!' }] }]"
/>
</a-form-item>
<a-form-item label="Gender" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
<a-select
v-decorator="[
'gender',
{ rules: [{ required: true, message: 'Please select your gender!' }] },
]"
placeholder="Select a option and change input text above"
@change="handleSelectChange"
>
<a-select-option value="male">
male </a-select-option>
<a-select-option value="female">
female </a-select-option>
</a-select>
</a-form-item>
<a-form-item :wrapper-col="{ span: 12, offset: 5 }">
<a-button type="primary" html-type="submit">
Submit </a-button>
</a-form-item>
</a-form></template><script>export default {
data() { return { formLayout: 'horizontal', form: this.$form.createForm(this, { name: 'coordinated' }),
};
}, methods: {
handleSubmit(e) {
e.preventDefault(); this.form.validateFields((err, values) => { if (!err) { console.log('Received values of form: ', values);
}
});
},
handleSelectChange(value) { console.log(value); this.form.setFieldsValue({ note: `Hi, ${value === 'male' ? 'man' : 'lady'}!`,
});
},
},
};</script>
发现,没有样式,只显示文字
因为只引入是不行的,还需要 注册组件 才能正常使用。
需要用到哪些组件,都要进行注册:
Vue.component(Form.name, Form);
Vue.component(Form.Item.name, Form.Item);
Vue.component(Input.name, Input);
Vue.component(Select.name, Select);
Vue.component(Select.Option.name, Select.Option);
这样组件就可以正常显示了。
声明:本文由w3h5原创,转载请注明出处:《Ant Design Vue引入Form组件样式不显示的解决方法》 https://cloud.tencent.com/developer/article/1542163
(adsbygoogle = window.adsbygoogle || []).push({});
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有