2017-10-18 69 views
0

我想將以下腳本嵌入到nuxtjs應用程序的組件中。但是由於Nuxt對此沒有解決方案。我想問vue社區,看看是否有更好的嵌入外部第三方js腳本的方法?如何整合mailchimp與nuxt js應用程序?

我應該在哪裏嵌入這種類型的scipt?我需要添加哪些外部配置才能使其工作?

我試着直接添加到我的模板,但它似乎並沒有工作。

<script type="text/javascript" src="//downloads.mailchimp.com/js/signup-forms/popup/embed.js" data-dojo-config="usePlainJson: true, isDebug: false"></script><script type="text/javascript">require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us17.list-manage.com","uuid":"XXXXXX","lid":"XXXXXX"}) })</script> 

謝謝!

回答

0

打開你的nuxt.config.js文件,並搜索頭對象。您可以在此加入您的第三方的腳本是這樣的:

// nuxt.config.js 
module.exports = { 
    head: { 
    title: 'My title', 
    // etc. 
    script: [ 
     { src: "//downloads.mailchimp.com/js/signup-forms/popup/embed.js" }, 
     // You can add multiple third-party scripts here 
    ] 
    }, 
    // Other stuff 
} 

文檔:How to use external resources?

我沒有測試過,但我覺得,因爲其他部分只是JavaScript中,您可以添加到您的網頁你wan't顯示它還是一個佈局文件(如果你想顯示其在多個頁面),像這樣:

// layout/default.vue 
<template> 
    <!-- Your template --> 
</template> 

<script> 
    require(["mojo/signup-forms/Loader"], function(L) { L.start({"baseUrl":"mc.us17.list-manage.com","uuid":"XXXXXX","lid":"XXXXXX"}) }); 
    export default { 
    // etc... 
    } 
</script> 

雖然需要一部分可能把事情搞得一團糟......

讓我知道這是否工作!

相關問題