javascript-使用RequireJS设置smooch-js
作者:互联网
我遵循了Smooch instructions,但没有成功.
这是我失败的最小代码:
<!doctype html><html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"></script>
<script>
require.config({
"paths": {
"smooch": "https://cdn.smooch.io/smooch.min"
}
});
// Tried this
require(["require", "smooch"], function(require){
var Smooch = require("smooch");
console.log(Smooch); // → undefined
});
// Tried that
require(["smooch"], function(Smooch){
console.log(Smooch); // → undefined
});
</script>
</head>
<body></body>
</html>
require给我返回了一个未定义的值,所以没有给我Smooch.init(…).经过Firefox和Chrome的测试.
难道我做错了什么 ?
解决方法:
您应该在您的require调用中使用“ Smooch”而不是“ smooch”,例如:
<!doctype html><html>
<head>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"></script>
<script>
require.config({
"paths": {
"Smooch": "https://cdn.smooch.io/smooch.min"
}
});
// Tried this
require(["require", "Smooch"], function(require){
var Smooch = require("Smooch");
console.log(Smooch); // → Smooch object
});
// Tried that
require(["Smooch"], function(Smooch){
console.log(Smooch); // → Smooch object
});
</script>
</head>
<body></body>
</html>
该库包装在UMD包装器中,并自定义其名称为“ Smooch”.
标签:requirejs,smooch,javascript 来源: https://codeday.me/bug/20191118/2030598.html