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

时间:2018-08-02 03:03:11

标签: javascript html vue.js nuxt.js 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

2 个答案:

答案 0 :(得分:2)

您可以尝试使用Tawk的Vue包装器。 vue-tawk

import Tawk from 'vue-tawk'

Vue.use(Tawk, {
    tawkSrc: 'YOU_TAWK_SRC'
})

答案 1 :(得分:2)

将tawk.to集成到nuxt项目中的最佳方法是: 转到nuxt.config.js并添加

 script:[
      {
        hid:"tawk.to",
        src:"https://embed.tawk.to/5edf699a9e5f694422903412/default",
        defer: true
      }
     ]