element-ui的NavMenu在摺疊以後,鼠標滑過menu在IE下,報錯.Error in v-on handler: "TypeError: 對象不支持此操做"

緣由在於element-ui的submenu代碼中多處使用了new MouseEvent('***'),可是ie中不支持該種操做。解決方案是:javascript

修改源碼(node_modules\element-ui\lib\element-ui.common.js )加上一個以下polyfill就行了。java

(function (window) {
  try {
    new MouseEvent('test');
    return false; // No need to polyfill
  } catch (e) {
		// Need to polyfill - fall through
  }

    // Polyfills DOM4 MouseEvent
	var MouseEventPolyfill = function (eventType, params) {
		params = params || { bubbles: false, cancelable: false };
		var mouseEvent = document.createEvent('MouseEvent');
		mouseEvent.initMouseEvent(eventType, 
			params.bubbles,
			params.cancelable,
			window,
			0,
			params.screenX || 0,
			params.screenY || 0,
			params.clientX || 0,
			params.clientY || 0,
			params.ctrlKey || false,
			params.altKey || false,
			params.shiftKey || false,
			params.metaKey || false,
			params.button || 0,
			params.relatedTarget || null
		);

		return mouseEvent;
	}

	MouseEventPolyfill.prototype = Event.prototype;

	window.MouseEvent = MouseEventPolyfill;
})(window);
相關文章
相關標籤/搜索