gpt4 book ai didi

javascript - 使用 RequireJS 设置 smooch-js

转载 作者:行者123 更新时间:2023-11-29 10:35:40 24 4
gpt4 key购买 nike

我关注了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 返回一个 undefined 所以没有 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”。

关于javascript - 使用 RequireJS 设置 smooch-js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36796682/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com