猿问

react 列表元素高度的获取

在用react做一个h5的项目,遇到了一个坑,我在componentDidMount里面获取不到正确的list元素高度,必须用到setTimeout才行,但是定时器也不靠谱啊, 有没有更好的解决办法呢

webpack.config.js配置文件

{


          test: /\.(js|mjs)$/,

          exclude: /@babel(?:\/|\\{1,2})runtime/,

          loader: require.resolve('babel-loader'),

          options: {

            babelrc: false,

            configFile: false,

            compact: false,

            presets: [

              [

                require.resolve('babel-preset-react-app/dependencies'),

                { helpers: true },

              ],

            ],

            cacheDirectory: true,

            cacheCompression: isEnvProduction,

            

            // If an error happens in a package, it's possible to be

            // because it was compiled. Thus, we don't want the browser

            // debugger to show the original code. Instead, the code

            // being evaluated would be much more helpful.

            sourceMaps: false,

          },

        },

        // "postcss" loader applies autoprefixer to our CSS.

        // "css" loader resolves paths in CSS and adds assets as dependencies.

        // "style" loader turns CSS into JS modules that inject <style> tags.

        // In production, we use MiniCSSExtractPlugin to extract that CSS

        // to a file, but in development "style" loader enables hot editing

        // of CSS.

        // By default we support CSS Modules with the extension .module.css

        {

          test: cssRegex,

          exclude: cssModuleRegex,

          use: getStyleLoaders({

            importLoaders: 1,

            sourceMap: isEnvProduction && shouldUseSourceMap,

          }),

          // Don't consider CSS imports dead code even if the

          // containing package claims to have no side effects.

          // Remove this when webpack adds a warning or an error for this.

          // See https://github.com/webpack/webpack/issues/6571

          sideEffects: true,

        },


大话西游666
浏览 2407回答 3
3回答

倚天杖

只在componentDidMount里获取,组件更新的时候就获取不到了,在componetUpdated里也获取一下吧

BIG阳

好奇问下这个 跟 webpack 有什么关系为什么还要贴这个配置
随时随地看视频慕课网APP
我要回答