0

In my functions.php file I have this code:

// Load both vue from the CDN as well as the scripts for the slideout cart and checkout
function load_vue_scripts()
{
    $scriptpath =  (get_stylesheet_directory_uri() . "/vue/slideout-cart/dist/slideout-cart.js");
    wp_register_script('vuejs_source', 'https://cdn.jsdelivr.net/npm/vue/dist/vue.js');
    wp_register_script('slideout-cart', "{$scriptpath}", 'vuejs_source', 1, true);
    plugin_dir_url(__FILE__) . "vue-cart/public/img"]);
//    echo $scriptpath;
    wp_enqueue_script('vuejs_source', 'https://cdn.jsdelivr.net/npm/vue/dist/vue.js');
    wp_enqueue_script('slideout-cart', "$scriptpath", 'vuejs_source', 1, true);
}

This loads Vuejs from the jsdelivr CDN, as well as loads my script from my the dist directory in my Vue app. Then, I create a div like so for my app to mount on:

<div id="slideout-cart" class="container" role="main"></div>

Then, I tell my app to mount on that div:

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#slideout-cart");

I see the script in my source tab on chrome, and I even see the console.log()'s coming from the app, but nothing is rendered. What am I doing wrong?

1
  • 1
    Looks fine to me, check if the component is loaded into the DOM (if the HTML is available within #slideout-cart). If so, check if there are styles which are hiding the element. Do you have the scripts available within the same page context (not within an iframe?) as the DOM element? Commented Feb 10, 2021 at 23:49

1 Answer 1

1

So as it turns out, I was doing everything right to render the app, but forgot to check my network tab and see that I wasn't sending the correct credentials to init the cart, so I was getting 401s back from my api and my app wasn't rendering at all

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.