webpack 大坑 ERROR in Template execution failed: ReferenceError: keyStr is not defined

  window.mystorage = {
        getItem: function (keyStr, cb) {
            var value = "";
            if (keyStr == "mobile_nextRootUrl") {
                value = "http://:8072/km"
            } else if (keyStr == "mobile_searchUrl") {
                value = "https:yunplatform/"
            } else if (keyStr == "mobile_docUrl") {
                value = "http://:8072/lua/download"
            } else if (keyStr == "mobile_iosUrl") {
                value = "http://0:8072/lua/iosview"
            } else if (keyStr == "mobile_nonce") {
                value = "8XzODXKc8XxcDXxNE"
            } else if (keyStr == "km_mobile_userName") {
                value = "张三"
            } else if (keyStr == "km_mobile_organizationId") {
                value = "43126"
            } else if (keyStr == "km_mobile_depId") {
                value = "23234"
            } else if (keyStr == "km_mobile_userId") {
                value = "172317"
            } else if (keyStr == "km_mobile_loginId") {
                value = "1256114"
            }
            // console.log(`keyStr:${keyStr}, value: ${value}`);//即使注释掉也报错 这里大坑提前写的话webpack识别不了keystr,没法打包
            cb(value)
        },

在html中写// console.log(`keyStr:${keyStr}, value: ${value}`);webpack无法翻译后来要传过来的值,打包报错

原因是,webpack打包最先执行,但是没有执行方法的话keyStr不是一个实际的值,是个变量,webpack无法翻译出来实际的值

你可能感兴趣的:(webpack)