我在页面上有简单的<script>连接和jquery。下面是示例:https://codepen.io/TidioSupport/pen/WNePeao
如何正确地将其添加到我的Vue组件中?因为当我尝试添加它时,我收到了:Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as they will not be parsed. or component not loading。
希望您的帮助,谢谢!
发布于 2021-04-20 02:20:16
在你的Vuejs的mounted lifecycle中,你可以追加脚本,然后使用它的函数。
这些脚本的变量可以通过window全局对象访问。
mounted() {
let chatScript = document.createElement('script')
chatScript.setAttribute('src', 'https://code.tidio.co/fouwfr0cnygz4sj8kttyv0cz1rpaayva.js')
document.head.appendChild(chatScript)
}发布于 2021-04-20 02:53:35
您应该将其添加到要调用vue应用程序的html的头部
https://stackoverflow.com/questions/67167150
复制相似问题