Skip to content Skip to sidebar Skip to footer

How To Integrate Mailchimp With Nuxt Js App?

I'd like to embed the following script into my component in nuxtjs app. But since nuxt has no solution for this. I'd like to ask the vue community to see if there was a better way

Solution 1:

Open up your nuxt.config.js file, and search for the head object. You can add your third party scripts there like this:

// nuxt.config.jsmodule.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
}

Docs: How to use external resources?

I haven't tested it, but I think, since the other part is just javascript, you can add into your page you wan't to show it or a layout file (if you want to show it on multiple pages), like this:

// 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"}) });
  exportdefault {
    // etc...
  }
</script>

Although the require part might mess things up...

Let me know if this works!

Solution 2:

Insert the MailChimp code inside the <head>

head() {
    return {
      script: [
        {
          type: "text/javascript", // mailchimp universal scriptsrc:
            "//downloads.mailchimp.com/js/signup-forms/popup/unique-methods/embed.js",
          "data-dojo-config": "usePlainJson: true, isDebug: false"
        },
        {
          type: "text/javascript", // mailchimp script for specific popup forminnerHTML: this.getMailchimp
        }
      ],
      __dangerouslyDisableSanitizers: ["script"]
    };
  },

  computed: {
    getMailchimp() {
      if (process.client) {
        returnJSON.stringify(
          window.dojoRequire(["mojo/signup-forms/Loader"], function(L) {
            L.start({
              baseUrl: "your base url",
              uuid: "your uuid",
              lid: "your lid",
              uniqueMethods: true
            });
          })
        );
      }
    }
  }

Post a Comment for "How To Integrate Mailchimp With Nuxt Js App?"