[Vuejs]-How to pass Laravel env data to Vue component

1๐Ÿ‘

โœ…

You need to remove the quotes. Webpack will interpolate the value for you:

<template>
{{ stripe }} // Renders process.env.MIX_STRIPE_KEY (Not the actual key?)
...code
</template>
<script>
export default {
    data: function() {
        return {
            stripe: Stripe(process.env.MIX_STRIPE_KEY),
...

Will compile as:

<template>
{{ stripe }} // Renders process.env.MIX_STRIPE_KEY (Not the actual key?)
...code
</template>
<script>
export default {
    data: function() {
        return {
            stripe: Stripe("pk_test_xxxxxxxxxxxxxxxxxx"),
...
๐Ÿ‘คEric Tucker

0๐Ÿ‘

Note for future readers: do not place your STRIPE_SECRET into Mix as this may make it exposed to the browser and any user that decides to snoop in it.

๐Ÿ‘คFlipper

Leave a comment