javascript - 在 Nuxt/Vue 应用程序中使用 tawk.to
问题描述
有谁知道如何在 Nuxt 应用程序中使用 tawk.to?
我使用以下代码在我的插件文件夹中创建了一个文件“tawk.js”:
var Tawk_API = Tawk_API || {},
Tawk_LoadStart = new Date()
(function () {
var s1 = document.createElement('script')
s0 = document.getElementsByTagName('script')[0]
s1.async = true
s1.src = 'https://embed.tawk.to/[my_ID_HERE]/default'
s1.charset = 'UTF-8'
s1.setAttribute('crossorigin', '*')
s0.parentNode.insertBefore(s1, s0)
})()
我也把它放在 nuxt.config.js 上:
plugins: [
{ src: '~/plugins/tawk.js', ssr: false }
]
它没有用。它确实显示了一些编译错误:
1:1 error Split initialized 'var' declarations into multiple statements
1:5 error Identifier 'Tawk_API' is not in camel case
1:16 error Identifier 'Tawk_API' is not in camel case
1:16 error 'Tawk_API' was used before it was defined
2:3 error Identifier 'Tawk_LoadStart' is not in camel case
2:3 error 'Tawk_LoadStart' is assigned a value but never used
2:29 error Unexpected space between function name and paren
3:3 error Unexpected newline between function and ( of function call
5:5 error 's0' is not defined
10:5 error 's0' is not defined
10:36 error 's0' is not defined
解决方案
tawk.to
集成到 nuxt 项目中的最佳方法是nuxt.config.js
将其添加为script
标签。
// nuxt.config.js
export default {
// ...
head: {
// ...
script: [
// ...
{
hid: 'tawk.to',
src:
'https://embed.tawk.to/5edf699a9e5f694422903412/default',
defer: true
}
]
},
},
推荐阅读
- azure-devops - 如何获取有关 Azure Devops 使用情况的统计信息?
- sql - Oracle Live SQL 不允许多行插入
- spring-kafka - 将 spring-kafka 更新到 2.4.0.RELEASE 时获取“java.lang.ClassNotFoundException:org.springframework.core.log.LogAccessor”
- r - 如何通过添加两列并赋予其中一个优先级来创建新列?
- javascript - 没有这个的另一个函数内部调用的函数上下文是什么?
- sql-server - Azure 数据库上的慢查询操作
- python - 如果任何数字是英镑,我如何从该输出中获得平均值并将货币转换为欧元?
- java - 为什么我有数组 [] 选项作为构造函数调用?
- rxjs - 等待 Observable 在 Array.Map 内部完成
- botframework - 有什么方法可以知道 Bot Activity 响应是否是最终响应?