Error encountered: Difficulty rendering Vue 3 components within Google Apps Script

Currently delving into Vue and Vue 3 while coding an application on Google Apps Script.

Following tutorials from Vue Mastery and stumbled upon a remarkable example by @brucemcpherson of a Vue 2 app functioning on GAS, which proved to be too challenging in certain aspects for me to grasp.

GitHub: https://github.com/brucemcpherson/bmVuetemplate

Encountering difficulty with components in GAS and Vue interplay, seeking assistance.

Here are the files I'm working with:

index.html

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
    <div id="app">
      <h1>{{ product }}</h1>
      </my-component></my-component>
    </div>
    <script src="https://unpkg.com/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a0d6d5c5e0938e908e908dc2c5d4c18e9192">[email protected]</a>/dist/vue.global.js"></script>
    <?!= include("main-js"); ?>
    <?!= include("my-component"); ?>
    <script>
      const mountedApp = app.mount('#app')
    </script>
  </body>
</html>

utils.gs

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

main-js.html

<script>
  const app = Vue.createApp({
      data() {
          return {
              product: 'Socks'
          }
      }
  })
</script>

my-component.html

<script>
  app.component('my-component', {
    template: `<div>My component content</div>`,
    data() {
          return {
              product: 'Boots'
          }
      }
  })
</script>

Seeing a warning on the console:

dropping postMessage.. was from host https://script.google.com but expected host https://n-jogxx7ovu3afq6djr4pskwjsglfwozzlkf5baay-0lu-script.googleusercontent.com

In both scenarios, nothing appears to happen: my component doesn't display when index.html is loaded.

Any insights on what the issue might be? Appreciate any help provided! Thanks!

Answer №1

Ensure that you start by initializing Vue before mounting the application. It's possible that this could have been the issue you encountered. Here is a functional codepen for reference. Additionally, I've included the imported Vue library in https://codepen.io/tzknc/pen/PopbOWW

<div id="app">
  <h1>{{ product }}</h1>
  <my-component/>
</div>

<script>
  // initialize the Vue instance 
  const app = Vue.createApp({
    data() {
      return {
        product: 'Socks',
      }
    }
  });
  // include the component 
  app.component('my-component', {
    template: `
    <div>
      My component content | {{product}}
    </div>`,
    data() {
          return {
              product: 'Boots'
          }
      }
  })
  // mount the Vue instance 
  const mountedApp = app.mount('#app')
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Comparing the use of input parameters to pass information in node.js versus the use

I'm grappling with the concept of when to inject a response into a function or call a function and retrieve something from it. Specifically in Node.js. Do functions in Node.js actually return data, or is it primarily about passing arguments and utili ...

Having trouble accessing data from the local storage?

const headers = new Headers({ 'access_token' : accToken, 'Content-Type': 'application/json', }); axios.post(baseURI, data, { headers: headers }) ...

Personalized 404 Error Page on Repl.it

Is it possible to create a custom 404-not found page for a website built on Repl.it? I understand that typically you would access the .htaccess file if hosting it yourself, but what is the process when using Repl.it? How can I design my own 404-not found p ...

Connect the AngularJS data model with a Foundation checkbox element

I am attempting to link a model (a boolean value) to a checkbox created with Foundation (Zurb). I have created a small demonstration displaying the issue: http://jsfiddle.net/JmZes/53/ One approach could involve simply creating a function that triggers o ...

Having trouble with a dropdown menu that allows for multi-select options?

var expanded = false; function showCheckboxes() { var checkboxes = document.getElementById("checkboxes"); if (!expanded) { checkboxes.style.display = "block"; expanded = true; } else { checkboxes.style.display = "none"; expanded = fa ...

function executed when meteor template finishes loading all content

Here is a template structure that I am working with: <template name="mainEvents"> <section class="main-events-list events-list js-content-slider"> {{#each events}} <div class="events-list-item"> &l ...

Vue.js function will only execute when the value is above zero

I've written a function that formats font color based on the returned value from a GraphQL non-nullable field. The values range from 0 to 10. It works perfectly for values between 1 and 10, but when the value is zero, it doesn't work as expected. ...

"Extending Material-UI: Utilizing Multiple Snackbar Components

I've been struggling to display multiple warnings using Snackbar from the Material UI library in my React project. I haven't found any examples with React, only Vue. Can anyone help me with this? Here is the code that I have tried so far: https: ...

Error with Cross-Origin Resource Sharing (CORS) on my website

During the development of a website, I disabled web security in order to bypass CORS using the command chrome.exe --disable-web-security --user-data-dir=/path/to/foo However, after successfully completing the website and uploading it to my domain, I enco ...

Transforming a datetime-local Element into a Date Object

I am currently utilizing the HTML5 element datetime-local with the requirement of having two different formats for the date. One format will be stored as a date object in the database, while the other format will be used as a string to set the datetime-loc ...

"Why is it that in a Vue object, only half the tag is needed in the line 'template: "<App/>'"?

Upon using the Vue webpack template, I came across code that looks like this: /* eslint-disable no-new */ new Vue({ el: '#app', router, template: '<App/>', // <-- components: { App } }) I understand what this code is ...

Resolving a Tricky Challenge with jQuery's

I am facing an issue with a function that animates images through crossfading. This function is responsible for rotating banners on a website. By calling the function as animateSlideshow("play"), it starts animating and sets up a timeout. On the other hand ...

The issue with Vue 3 v-model is that it fails to properly update values stored within an

I am currently developing a simple app using VUE in which I carry out the following tasks: Download a list of items from a database (supabase) and store it in an array List the items in the array on a page with editable fields Save any updated values back ...

The automated test locator in Angular using Protractor is failing to function

I am facing a challenge with my angular web application as there are some elements that are difficult to interact with. One specific element is a checkbox that needs to be checked during testing: ` <div class="row form-group approval_label"> < ...

Python API integrated website experiencing deployment issues on Github Pages

We are working on a group project with two other members, implementing a CRUD system using HTML, CSS, Vue.js, and an API hosted on pythonanywhere. We have successfully tested the system locally and it connects to pythonanywhere without any issues. However, ...

npm update fails to update specific packages

After React was updated to version 0.15 to address the issue of excessive generation of tags, I made the decision to update my project.</p> <p>However, when I ran the command <code>npm update, it only updated to version 0.14.8. Running ...

JavaScript regular expression to switch menu

Could someone clarify the meaning of this code snippet: /expanded/.test(classes) I understand that the '/' characters indicate a regular expression and 'expanded' is a class name. However, I am unsure about what .test(classes) does ...

Switch the text display by clicking on a different button in the list

I am currently dealing with an issue involving a list of boxes containing text/images and buttons for expanding/collapsing the text. Whenever I click on another item's button, the text box that was previously opened gets closed, but the button text re ...

Enhance the collapsible feature in Vue.js by integrating Bootstrap and anim

In the process of creating a side bar menu with collapse show/hide functionality, I am encountering some issues. The current CSS implementation is making the collapse action appear abrupt and unnatural. I am looking to achieve a smooth sliding transition ...

The issue arises when PhantomJS and Selenium fail to execute iframe JavaScripts while attempting to log in to Instagram

Currently utilizing Python alongside Selenium and PhantomJS, I encountered an issue while attempting to login to Instagram. It seems that PhantomJS is unable to process iframes' JavaScripts properly; interestingly, when trying the same action with Fir ...