The CSS for the balise component is failing to load within a particular component

I'm facing an issue with loading the CSS of my bloc component.

The webpage component allows for easily creating an iframe and setting content inside.

While it correctly loads the template and script tags, the CSS doesn't always load properly.

Sometimes it works, but most of the time, it doesn't.

I initially thought it was a loading issue with the component itself, but that's not the case.

Whether I load the component before or after rendering my "webpage" component, the CSS still won't load.

I've tried changing the auto import to true and then false, but it doesn't resolve the issue.

I have 2 components: webpage and bloc.

bloc.vue

<template>
  <div class="bloc">
    <p>The text</p>
  </div>
</template>

<style>
.bloc {
  background-color: blue;
  padding: 20px;
}
</style>

webpage.vue

<script>
import Vue from "vue";
export default {
  props: {
    css: {
      type: String,
      required: false,
    },
  },
  data() {
    return {
      load: false,
    };
  },
  render(h) {
    return h("iframe", {
      on: { load: this.renderChildren },
    });
  },
  beforeUpdate() {
    //freezing to prevent unnecessary Reactification of vNodes
    this.iApp.children = Object.freeze(this.$slots.default);
  },
  mounted() {
    if (!this.load) this.renderChildren();
  },
  methods: {
    // https://forum.vuejs.org/t/render-inside-iframe/6419/12
    renderChildren() {
      this.load = true;
      const children = this.$slots.default;
      const head = this.$el.contentDocument.head;
      const body = this.$el.contentDocument.body;

      let style = this.$el.contentDocument.createElement("style");
      style.textContent += this.$props.css;
      head.appendChild(style);

      const iApp = new Vue({
        name: "iApp",
        // freezing to prevent unnecessary Reactification of vNodes
        data: { children: Object.freeze(children) },
        render(h) {
          return h("body", this.children);
        },
      });

      this.iApp = iApp; // cache instance for later updates
      this.iApp.$mount(body); // mount into iframe
    },
  },
};
</script>

app.vue

<template>
  <Webpage>
    <component :is="name"></component>
  </Webpage>
</template>

<script>
import bloc from "@/components/Bloc";
import Webpage from "@/components/Webpage";
export default {
  components: {
    bloc,
    Webpage,
  },
  computed: {
    name() {
      return "bloc";
    },
  },
};
</script>

Any insights on where this issue might be stemming from?

Link to the codesandbox: https://codesandbox.io/s/error-style-component-import-1t1hs?file=/pages/index.vue

Thank you.

Answer №1

It's likely that the Webpage component is taking precedence.
Consider relocating your CSS to the index file and use

<Webpage class="bloc">

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

Send an array using jQuery's $.post method

I am experiencing an issue with sending an array in $.post to PHP. When I use var_dump, the result is showing as "NULL" and JSON.stringify is not working. JQUERY var photobox = []; photobox.push(e.target.result); $.post("../modules/upload.php",{"imag ...

Puppeteer's flawed performance leads to the generation of low-quality

Currently, I am utilizing puppeteer to generate a PDF from my static local HTML file. However, the resulting PDF is turning out to be corrupted. When attempting to open the file using Adobe Reader, an error message pops up stating 'Bad file handle&apo ...

Implementing URL routing and error handling in a Node.js application using the Express framework

As a newcomer to node.js, I appreciate your patience. I've been experimenting with node.js and the express module. I had an idea for handling browser requests and now I have a simple question: Is this approach good practice, or is there a better sol ...

Numerous criteria for selecting a checkbox

I am working with a student database table called student_db, which looks like this: Name Gender Grade City John Male 2 North Dave Male 4 North Garry Male 3 North Chirsty Female 5 East Monica Female 4 East Andrew Male ...

Using jQuery to calculate mathematical operations in a form

I've been working on creating a form that calculates the total cost based on selected options. So far, I've managed to get it working for three options, but I'm stuck on how to calculate the subtotal by adding the variables "vpageprice" and ...

Stopping autoplay in React Swiper when hovering over it

I'm currently struggling to find a way to pause the autoplay function on swiper when hovering over it. Despite my efforts, I have not been able to locate a solution. <Swiper spaceBetween={0} navigation={{ ...

Press anywhere outside the container to conceal it along with the button

Utilizing an Angular directive to hide div elements when the user interacts outside of them has been effective. However, there is a specific issue that arises when clicking outside of a div on a button that toggles the visibility of the div. The 'ang ...

What is the best way to dissect emails using Haraka?

After delving into the haraka project (at ), I managed to successfully install it on my linux machine. Now, I'm interested in finding a comprehensive tutorial on parsing email meta headers and content body using haraka. Despite searching through their ...

Is there a way to ensure that the div of my template spans 100% in width and height?

I'm attempting to make my div 100% in size but I am having trouble achieving it. Here is my code: <template> <div> <Navbar/> <Calendar/> </div> </template> <script setup> import Calendar from &apos ...

"ExceptionThrownByMoveTargetOutOfBounds in Selenium WebDriver for IE9 and Firefox

Having trouble with the FireFox/IE9 driver in Selenium? When using the Actions class and its moveToElement method, I keep encountering a MoveTargetOutOfBoundsException error. Despite trying different solutions like Coordinates, Point, and javascriptexecuto ...

I am unable to send back my JSON object

I seem to be having trouble returning a JSON object as all I get is an undefined variable. The code below is supposed to fetch a JSON element from an API. It appears to work within the success: function, but when attempting to use that data elsewhere, it ...

Encountering an issue while trying to initiate a fresh React Native Project

As I work through the setup steps outlined in the React Native Documentation on my M1 MacBook Pro, I encounter a stumbling block. Despite successfully running React projects and Expo projects on this machine before, I hit a snag when trying to create a new ...

Discover how to obtain an access token using Yelp API V3 with JavaScript

Currently in the process of learning how to utilize this system, however there appears to be an issue with my code. $.ajax({ dataType: "POST", url: "https://api.yelp.com/oauth2/token", grant_type: "client_credentials", client_i ...

Vue.js SyntaxError: Identifier came out of nowhere

An error was reported by VUE debug mode in this line of my code: :style="{transform : 'translate3d(' + translateX + 'px,0, 0)'}"\ The documentation does not provide instructions on how to include a variable within a style binding ...

What is the best way to implement function chaining in TypeScript?

I'm interested in implementing function chaining in typescript. Let's consider a sample class: export class NumberOperator { private num; constructor(initialNum) { this.num = initialNum; } public add(inc = 1) { this.num += inc ...

The child element's data is not interacting or responding as expected

I have a child component that displays search results. Snippet from the parent template: <result v-for="result in search_results" :item="result" :closeAllServices="closeAllServices"></result> Below is the child (result) template: <templa ...

What is the best way to dynamically display or hide a component in the header of my Vue 3 application based on the current route in

I am looking for a way to dynamically show or hide a button in the navigation bar of my web application based on the current router path in my Vue.js application. The HeaderComponent contains the main navigation elements. I have been struggling to find a ...

Stopping the execution of jQuery().load()

The .load() feature in the jQuery library allows users to selectively load elements from another page, based on specific criteria. I am curious to know if it's feasible to stop or cancel the loading process once initiated. In our program, users can e ...

Having difficulties generating a vue-web-extension using vue-cli

Currently, I am in the process of enhancing a chrome extension by adding a new popup page developed in Vue. The tutorial I am referring to for this task can be found at . However, when attempting the step vue init kocal/vue-web-extension my-extension, I e ...

Change this npm script into a gulp task

I have a script in npm that I would like to convert into a gulp task. "scripts": { "lint": "eslint .", "start": "npm run build:sdk && node .", "posttest": "npm run lint && nsp check", "build:sdk": "./node_modules/.bin/lb- ...