Skip to content

IE11环境下Input组件清空异常 #2592

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

Closed
1 task
hy08 opened this issue Jul 22, 2020 · 7 comments
Closed
1 task

IE11环境下Input组件清空异常 #2592

hy08 opened this issue Jul 22, 2020 · 7 comments

Comments

@hy08
Copy link

hy08 commented Jul 22, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

1.6.4

Environment

browser: IE11 ant-design-vue: 1.6.1

Reproduction link

Edit on CodeSandbox

Steps to reproduce

基础的Input组件,声明allowClear属性,chrome删除正常,ie11报错:Error in v-on handler: "TypeError: strict 模式下不允许分配到只读属性"

What is expected?

ie可以正常删除

What is actually happening?

Error in v-on handler: "TypeError: strict 模式下不允许分配到只读属性"

@labike
Copy link

labike commented Jul 22, 2020

这是严格模式下导致的

首先这是发生在event上的, 在源码内部是这样实现点击清除图标清除输入内容的

function resolveOnChange(target, e, onChange) {
  if (onChange) {
    var event = e;
    if (e.type === 'click') {
      // click clear icon
      //event = Object.create(e);
      Object.defineProperty(event, 'target', {
        writable: true
      });
      Object.defineProperty(event, 'currentTarget', {
        writable: true
      });
      event.target = target;
      event.currentTarget = target;
      var originalInputValue = target.value;
      // change target ref value cause e.target.value should be '' when clear input
      target.value = '';
      onChange(event);
      // reset target ref value
      target.value = originalInputValue;
      return;
    }
    onChange(event);
  }
}

可以看到这里对event的target进行了劫持并修改了writeable, target属性中有个configureable属性,该属性默认为false表示对象上的属性是只读的, 在严格模式下修改是会报`typeError '

@wayne950921
Copy link

想问这个问题解决了吗

@hy08
Copy link
Author

hy08 commented Sep 22, 2020

想问这个问题解决了吗

我放弃在IE11中使用清除功能了

@liuqingchao
Copy link

liuqingchao commented Sep 28, 2020

分享一下我的方法:
import { Input } from 'ant-design-vue'
if (!!window.ActiveXObject || 'ActiveXObject' in window) {
Input.methods.handleReset = function (e) {
this.stateValue = ''
this.$emit('change.value', '')
}
}

@sanmaozhao
Copy link

遇到了同样的问题

@github-actions
Copy link

github-actions bot commented Feb 6, 2021

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants