前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ant Design Vue引入Form组件样式不显示的解决方法

Ant Design Vue引入Form组件样式不显示的解决方法

作者头像
德顺
发布2019-11-21 17:00:49
7.2K0
发布2019-11-21 17:00:49
举报
文章被收录于专栏:前端资源

使用 vue-cli 安装 Ant Design Vue 的 Form 组件,发现不能用,组件样式不显示。

此处省略了安装和初始化的步骤,需要的点击上方链接,直接在 Ant Design 官网查看教程

在 main.js 中全局引入:

代码语言:javascript
复制
import { Form, Input, Select } from 'ant-design-vue';

因为我进行了 按需加载组件代码 的配置,所以只需要上面一行就可以。

引用官网的一个基础示例:

代码语言:javascript
复制
<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>

发现,没有样式,只显示文字

因为只引入是不行的,还需要 注册组件 才能正常使用。

需要用到哪些组件,都要进行注册:

代码语言:javascript
复制
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

代码语言:txt
复制
     (adsbygoogle = window.adsbygoogle || []).push({});
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档