Stop vuetify from cluttering the global style scope

Seeking to embed a Vue component into another from an external source without using a Vue Plugin. The components are mounting correctly, but the embedded component's use of Vuetify is affecting the parent application's style. Visual examples can be seen below:

Before mounting the embedded component, notice the primary colors of the root application:

https://i.stack.imgur.com/Op9Uz.png

After mounting the Login (embedded) component:

https://i.stack.imgur.com/N5vsa.png

Attempted a strategy mentioned here, using less in the embedded component to import Vuetify css at a block level, but it did not work.

Realizing that making sure the embedded theme matches the root application's theme could solve the issue, however, I prefer not to rely on that solution. If my component is built with webpack, why am I unable to apply Vuetify's css just to that specific component? Any suggestions?

I am willing to provide code if needed

Answer №1

If you're working with vue.js, make sure to install postcss-parent-selector

npm i postcss-parent-selector -D

Next, create a postcss.config.js file in your root directory and include the following code:

module.exports = {
  plugins: [
    require("postcss-parent-selector")({
      selector: ".mywrapperclass",
    }),
  ],
};

After that, add a wrapper element around your app in public/index.html:

<div class="mywrapperclass">
  <div id="app"></div>
</div>

Here are some helpful links for reference:

Answer №2

I am currently experiencing a similar issue with my application. I have considered a few potential solutions:

-One option is to embed the child Vue application using an iframe and utilize a library like vuex-iframe-sync to share props between the Vuetify root app and the child app.

-Another approach could be to completely disable the Vuetify theme and potentially customize components independently:

// src/plugins/vuetify.js

import Vue from 'vue'
import Vuetify from 'vuetify/lib'

const vuetify = new Vuetify({
  theme: { disable: true },
})

-I also explored the idea of using webpack configuration to implement a PostCSS plugin and potentially apply prefixes to Vuetify's global styles during the app bundling process, but I encountered challenges in implementing this.

If you make any headway on this matter, please update me!

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

Can Stencil.js be utilized to link and include multiple Stencil projects within a single Vue.js Project?

I encountered an issue while attempting to import multiple Stencil.js projects into my Vue project. Following the instructions provided for a single stencil project from this resource: However, when trying to import applyPolyFills and defineCustomElements ...

Should we bundle everything into one script with webpack, considering Npm and Dev dependency or just dependencies?

Imagine a scenario where we use webpack to bundle all our code into a single JS file, which automatically imports dependencies. In this case, is it necessary to include any dependencies in the package.json, or can they all be listed as --save-dev? Let&apo ...

Troubleshooting route issues with node.js and vue application hosted on Azure

After successfully deploying a node js ap with a Vue frontend on azure, I encountered an issue where visiting a URL that is not the root resulted in a white screen displaying the message 'CANNOT GET /products' as an example. Within the root of t ...

Set styles to child elements of an external component using styled-components

In my Component.tsx file, I am using the following template: import {Foo} from 'external-stuff' <Foo> <p>bar</p> </Foo> The Foo component is designed to accept a className parameter. const Foo = ({className, title}) =& ...

Is there a way to switch the default text mode from plain to code, such as HTML?

Is there a way to switch from plain text mode to code mode, specifically HTML, in Sublime? I often find the need to change the mode from plain text to HTML when working on projects. ...

What is the best way to position two out of the three link tags to the right side?

This is the code snippet I am currently working with: <table> <tr> <td>&nbsp;</td> <td> <a id="btnAutoSuggest">Suggest Title</a> <a id="btnOK">OK</a> <a id ...

Angular 12 experiencing CSS alignment issues

In my Angular component, I have the following CSS: .folders { border-left: 5px solid #b8744f; -moz-border-radius: 5px; -webkit-border-radius: 5px; -moz-box-shadow: inset 0 0 1px #fff; -webkit-box-shadow: inset 0 0 1px #fff; /*CORRECTION NEEDED ...

What is the best way to address cookie issues while working on a full stack application that utilizes Vue and Express.js?

Developing a full stack application requires me to use Vue on port 5173 and Express on port 3000. One issue I face is the inability to store credentials in the frontend for backend communication during development. This challenge can be addressed by servin ...

How can I align text to the bottom right and left corners at the same time?

Is there a way to align text so that it appears in both the bottom right and bottom left corners of the page, functioning as a footer? For example: JANUARY (bottom left corner) / 2019 (bottom right corner) If anyone knows how to achieve this using HTML ...

Error: The virtual file system could not locate the file 'Roboto-Regular.ttf' within the DataTable component in vuejs

I am currently facing an issue with vuejs - DataTable where I encounter an error while trying to generate a PDF report of the tables. Interestingly, generating an Excel report works perfectly fine. Below is my form code snippet: <table id="examp ...

What is the best way to include multiple font styles for different tags?

While working on a website project, the client requested to use Roboto as the main font (by Google). Different styles of Roboto such as Roboto Thin or Roboto Light were used for various elements on the page. However, I utilized the @font-face selector to e ...

Using Vue.js to conditionally render data in a v-for loop

Below is the code snippet I am working with: <article class="project-card" v-for="item in en.projects" Additionally, here are some import statements: import fr from '../assets/datas/fr.json' import en from '../assets/datas/en. ...

"Troubleshooting a CSS Problem in the ADF

I've encountered a serious issue with my ADF Application starting yesterday. Everything was running smoothly until suddenly, I saw this unexpected message in my Jdeveloper Console: < org.apache.myfaces.trinidadinternal.style.util.CSSUtils> < ...

Jumping CSS dropdown menu glitch

I'm facing an issue with a dropdown menu. The main problem is that the "parent" link is moving when hovered over. HTML: <ul id="nav"> <li><span>Page 1</span> <ul> <li><a>Extralong Pag ...

Encountering a 404 Error in CKFinder 3 integration with Laravel 6 and Vuejs while accessing the File Browser

My progress so far includes almost being able to successfully upload files to my Laravel installation using CKEditor and the CKFinder file browser opening from the route myurl/ckfinder/browser. However, I have encountered an issue where clicking on the ima ...

Unable to implement the `omega/theme.css` file within the angular.json configuration

"styles": [ "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css", "node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.css", "node_modules/primeicons/primeicons.css", ...

Could my mental model be flawed? When a page is accessed using https, a relative css path will be invoked using the same protocol

When your page is accessed using the https protocol, any relative path to an external CSS file will also be called using the https protocol. Do you really need to encrypt/decrypt CSS content? :D However, if you use an absolute path to reference an external ...

Can child components forward specific events to their parent component?

I created a basic component that triggers events whenever a button is clicked. InnerComponent.vue <template> <v-btn @click="emit('something-happened')">Click me</v-btn> </template> <script setup lang=" ...

I have been working on creating a horizontal menu, but encountered an issue where the nav tag is unable to accommodate all the ul lists within itself

My latest project involves a menu with three separate divs: logo, nav-bar, and right-bar. I decided to use justify-content: space-around to position the elements - the logo on the left, navigation in the center, and right-bar on the right. However, when I ...

creating a div element with a height that matches its content dimensions

I'm having trouble creating a navigation bar because the outer div isn't matching the height of the unordered list inside it. I attempted using display:inline-block as well, but it didn't solve the issue. Here is the HTML: http://jsfiddle ...