Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery url.indexOf不是一个函数_Javascript_Jquery_Webpack 2 - Fatal编程技术网

Javascript jQuery url.indexOf不是一个函数

Javascript jQuery url.indexOf不是一个函数,javascript,jquery,webpack-2,Javascript,Jquery,Webpack 2,我刚刚使用安装了jQuery npm install jquery 在使用Webpack将jquery、bootstrap合并到一个供应商文件中之后,我不断得到以下错误 vendor.4b59d15129c2efa4408c.js:9979 Uncaught TypeError: url.indexOf is not a function at jQuery.fn.init.jQuery.fn.load (vendor.4b59d15129c2efa4408c.js:9979)

我刚刚使用安装了jQuery

npm install jquery
在使用Webpack将jquery、bootstrap合并到一个供应商文件中之后,我不断得到以下错误

vendor.4b59d15129c2efa4408c.js:9979 Uncaught TypeError: url.indexOf is not a function
    at jQuery.fn.init.jQuery.fn.load (vendor.4b59d15129c2efa4408c.js:9979)
    at Object.<anonymous> (bundle.7beebbf8c43d73f31563.js:55)
    at Object.<anonymous> (bundle.7beebbf8c43d73f31563.js:213)
    at __webpack_require__ (vendor.4b59d15129c2efa4408c.js:55)
    at Object.<anonymous> (bundle.7beebbf8c43d73f31563.js:12)
    at __webpack_require__ (vendor.4b59d15129c2efa4408c.js:55)
    at webpackJsonpCallback (vendor.4b59d15129c2efa4408c.js:26)
    at bundle.7beebbf8c43d73f31563.js:1
vendor.4b59d15129c2efa4408c.js:9979未捕获类型错误:url.indexOf不是函数
位于jQuery.fn.init.jQuery.fn.load(vendor.4b59d15129c2efa4408c.js:9979)
反对。(捆绑包7BEEBF8C43D73F31563.js:55)
反对。(bundle.7beebf8c43d73f31563.js:213)
at网页要求(供应商:4b59d15129c2efa4408c.js:55)
反对。(bundle.7beebf8c43d73f31563.js:12)
at网页要求(供应商:4b59d15129c2efa4408c.js:55)
在webpackJsonpCallback上(供应商:4b59d15129c2efa4408c.js:26)
在bundle.7beebf8c43d73f31563处。js:1

我假设url是一个字符串,所以我推断这是一个问题,当您设置url时,尝试查找该行并替换为console.log(url)以查看它是否已定义。

在代码中更改此项:

off = url.indexOf( " " );
致:


简而言之,您试图访问
null
undefined
上的
indexOf
,这会引发该错误。所以我要做的是检查url是否存在,然后访问indexOf,否则设置为-1,如果url不包含空字符串,
indexOf
将返回该值。

您的jQuery版本是什么?在版本3上,不推荐使用函数
$(window).load()
。当使用
.load()
.unload()
.error()
时,它将抛出一个错误

将这些功能替换为:

旧的

$(窗口).load(函数(){})

以上第3版

$(窗口).on('load',函数(){})

$(窗口).on('error',function(){})

我自己的案例是在
Vue.js
中使用SuperSimpleSlider jQuery插件。我必须用正确的解决方案替换原始文件(插件)

希望这有帮助

资料来源:

你的代码在哪里?我现在已经更新了为什么你要覆盖jQuery的函数?如果你能在最新的jQuery 3.2.1中使用clt+f并键入url.indexof,我不会覆盖任何函数。你会看到与我在jsfiddle中提到的相同的函数,这里是链接或控制台.log(typeof(url))
off = url ? url.indexOf( " " ) : -1;