ant-design-vue常见问题

最近的项目使用ant-design-vue, 细节上遇到一些小问题,解决方法记下来,备以后速查。

使用Message全局提示

代码中的写法

this.$message.success("添加成功");

上面这种写法会提示 $message 为 undefined

解决方法

import { message } from "ant-design-vue";
// 这里省略其他代码
Vue.prototype.$message = message;

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");

使用confirm确认对话框

代码中的写法

this.$confirm({处理逻辑})

问题和上面一样 $confirm 为 undefined

解决方法

import { Modal } from "ant-design-vue";
// 这里省略其他代码
Vue.prototype.$confirm = Modal.confirm;

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");

给Modal中的表单赋值

场景

在一个弹框中写一个表单,进行数据修改。在表单弹出之前先给表单内数据赋值

问题

报错 You cannot set a form field before rendering a field associated with the value.

解决方法

把赋值语句放到 nextTick中去

methods: {
    onEdit(record) {
      this.editMode = true;
      this.visible = true;
      this.errMsg = "";
      this.roleId = record.roleId;
      this.$nextTick(() => {
        this.form.setFieldsValue({ roleName: record.roleName });
      });
    },
    ... //其他方法
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值