简体   繁体   English

在 Nuxt/Vue 应用程序中使用 tawk.to

[英]Using tawk.to with Nuxt/Vue Application

Does anyone know how to use tawk.to in a Nuxt application?有谁知道如何在 Nuxt 应用程序中使用 tawk.to?

I created a file "tawk.js" on my plugin folder with the following code:我使用以下代码在我的插件文件夹中创建了一个文件“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)
  })()

And I put it on nuxt.config.js as well:我也把它放在 nuxt.config.js 上:

  plugins: [
    { src: '~/plugins/tawk.js', ssr: false }
  ]

It didn't work.它没有用。 It does show some compiled errors:它确实显示了一些编译错误:

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

The best way to integrate tawk.to in nuxt project is to go to nuxt.config.js and add it as a script tag.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
            }
        ]
    },
},

You could try to use a vue wrapper for tawk.您可以尝试使用 tawk 的 vue 包装器。 vue-tawk vue-tawk

import Tawk from 'vue-tawk'

Vue.use(Tawk, {
    tawkSrc: 'https://embed.tawk.to/5d5528ee2xxxxxxxxxxxx/default'
})

This may be late, but for future people who wanted to use tawk in Vue/Nuxt.这可能为时已晚,但对于未来想在 Vue/Nuxt 中使用 tawk 的人来说。 You can use different version for Vue2/Nuxt2 and Vue3/Nuxt3您可以为Vue2/Nuxt2Vue3/Nuxt3使用不同的版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 i18next 在语言更改时重新加载 tawk.to 小部件? - How to reload tawk.to widget on language change using i18next? 使用文本链接打开 tawk.to 的小部件聊天时出现问题..谁能帮我解决这个问题? - Problem in using text link to open widget chat of tawk.to ..Can anyone help me with this? Tawk.to小部件问题在移动(AngularJS)上 - Tawk.to widget issue on mobile (AngularJS) Rails:Tawk.to 聊天插件和 Turbolinks 问题 - Rails: Tawk.to chat plugin and Turbolinks issue Tawk.to href="javascript:void(Tawk_API.toggle())" 替代 - Tawk.to href="javascript:void(Tawk_API.toggle())" alternative Tawk.to无法在IONIC应用程序内工作,但在已部署的浏览器上工作 - Tawk.to Not working inside an IONIC App but working on deployed browser 实时聊天 Jquery 插件 tawk.to 不可见 - Live-chat Jquery plugin tawk.to not visible 内嵌样式 CSP 违规 tawk.to 嵌入式聊天小部件 - inline styling CSP violation tawk.to embedded chat widget 如何通过phonegap在混合移动应用程序上使用tawk.to API? - How to use tawk.to API on hybrid mobile app by phonegap? 外部 Java 脚本反应 Redux (Tawk.to) 卸载 - External Java Script React Redux (Tawk.to) Unmount
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM