无法在 IE9/10 中获取属性 ReactJS 的值

Unable to get value of the property ReactJS in IE9/10

本文关键字:获取 属性 ReactJS 的值 IE9      更新时间:2023-09-26

我有一个反应组件,我使用以下代码将其渲染到 DOM 中:

ReactDOM.render(React.createElement(PROJECT.CalendarApp, 
        {   key                     : 'globalcalendar', 
            roomPage                : false, 
            localeRegion            : PROJECT.user.locale().region,
            localeStartDay          : PROJECT.user.locale().startDay,
            showCalendarOnLoad      : false,
            name                    : 'globalcalendar',
            availabilityCalendar    : false 
        }), 
    document.getElementById('global_calendar_component'));

我在IE 9/10中收到以下错误,似乎无法弄清楚原因 - Unable to get value of the property 'localeRegion' object is null or undefined reactjs

PROJECT.user.locale().region定义正确并返回一串 'en'

此问题仅在IE 9和10中发生,目前我的webpack设置如下所示:

var webpack = require('webpack');
var path = require('path');
var BUILD_DIR = path.resolve(__dirname, '../src/Family/SystemBundle/Resources/public/js/components/compiled');
var APP_DIR = path.resolve(__dirname, '../src/Family/SystemBundle/Resources/public/js/components/');
var config = {
    entry: {
        calendar    : APP_DIR + '/calendar.jsx'
    },
        output: {
            path: BUILD_DIR,
            filename: '[name].js'
        },
    module : {
        loaders : [
            {
                test : /'.jsx?/,
                include : APP_DIR,
                loader : 'babel',
                query:
                {
                    presets:[require.resolve('babel-preset-es2015'), require.resolve('babel-preset-react')] // Brackets - required for babel symlinking because node_modules is not in the root folder.
                }
            }
        ]
    }
};
module.exports = config;

我已经将 Babel Polyfill 加载到项目中,并且对这个问题感到非常困惑。如果有人经历过类似的事情,那么很高兴知道您是如何解决它的。

我们终于找到了这个问题的答案。问题是IE9不喜欢在react组件的构造函数中使用props,但允许在其他组件方法中使用props。

要解决此问题,请不要在构造函数中使用任何 props,或者尝试在 webpack 文件中使用 plugins: [['transform-es2015-classes', {loose: true}]]

更多詳情請參閱:https://phabricator.babeljs.io/T3041 & https://phabricator.babeljs.io/T6954