I am working with laravel app that renders the Vuejs component into blade laravel, it renders the component but it's affected with CSS design of laravel backend cause I preview the component in the backend part, my question is how can I split the CSS design of my Vuejs component from laravel CSS design backend?
header-component.vue
<template>
<div>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
</div>
</template>
<style scoped>
.container{
width: 960px;
margin:auto;
}
</style>
<style>
@import '/../frontend/css/all.css';
@import '/../frontend/css/Animate.css';
@import '/../frontend/css/bootstrap.min.css';
@import '/../frontend/css/owl.carousel.min.css';
@import '/../frontend/css/responsive.css';
@import '/../frontend/css/style.css';
.main-header{
position: relative;
}
.parellex{
margin-top: -125px;
}
</style>
header.blade.php
@extends('master.app')
@section('content')
<div style="overflow:auto; position:relative; top: 30px; left:0; right:0; bottom:0" class="mr-5 ml-5">
<header-component></header-component>
</div>
@endsection
app.blad.php
<html lang="{{str_replace('_', '-', $lang = app()->getLocale()) }}" dir='{{ $lang=="ar"? "rtl" : "ltr" }}' style="--primarycolor:#17b3a3;">
<head>
{{-- {{ dd($lang, Cookie::get('lang')) }} --}}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'MyApp') }}</title>
<?php $dir = $lang == "ar"? "rtl":"ltr" ?>
<!-- START: Template CSS-->
<link rel="stylesheet" href="{{ asset('backend/'.$dir.'/vendors/bootstrap/css/bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ asset('backend/'.$dir.'/vendors/jquery-ui/jquery-ui.min.css') }}">
<link rel="stylesheet" href="{{ asset('backend/'.$dir.'/vendors/jquery-ui/jquery-ui.theme.min.css') }}">
<link rel="stylesheet" href="{{ asset('backend/'.$dir.'/vendors/simple-line-icons/css/simple-line-icons.css') }}">
<link rel="stylesheet" href="{{ asset('backend/'.$dir.'/vendors/flags-icon/css/flag-icon.min.css') }}">
<link rel="stylesheet" href="{{ asset('backend/'.$dir.'/vendors/flag-select/css/flags.css') }}">
<!-- END Template CSS-->
<body id="main-container" class="default light small-menu-icon">
<div id="app">
<!-- START: Main Content-->
<main>
<div class="container-fluid">
@include('flash::message')
<!-- START: Breadcrumbs-->@auth
@include('master.partials.breadcrumbs')
<!-- END: Breadcrumbs-->@endauth
@yield('content')
</div>
</main>
<!-- END: Main Content-->
</div>
</body>
</html>
So my question how could I split the design between backend and frontend(Vuejs components)? any Idea or tips, I will be appreciated.
Style Scopes
You can start by scoping the styles for each Vuejs Components
<style scoped>
.foo {
background: red
}
</style>
Using Webpack
In yourwebpack.mix.js
you need to split your resources.
mix.styles(['resources/css/frontend.css'], 'public/css/frontend.css')
mix.styles(['resources/css/backend.css'], 'public/css/backend.css')
Using this in your Laravel application
<!-- Inside backend layout -->
<link rel="stylesheet" href="{{ mix('css/backend.css') }}">
<!-- Inside frontend layout -->
<link rel="stylesheet" href="{{ mix('css/frontend.css') }}">
Not sure which parts are fighting. All the libraries you're loading or the custom code for the component.
First I'd try to load libraries only once. For example, you probably only need one copy of bootstrap.
Second, if its the component code that's fighting (egmain-header
) you can addscoped
to your Vue Style tags. This makes the styling AND classes unique to that component.
However, I'm not sure what will happen if you make all those imports scoped to the component as well.
I think you're better off, loading all those library components into the whole Vue project (import into main.js) instead of in the component itself. That way you can conditionally load things depending on the environment you're using.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
JQuery is arguably the most popular JavaScript library with so many features for modern development. JQuery is a fast and concise JavaScript library created by John Resig in 2006. It is a cross-platform JavaScript library designed to simplify client-side HTML scripting. Over 19 million websites are currently using jQuery! Companies like WordPress, Facebook, Google, IBM and many more rely on jQuery to provide a kind of web browsing experience.
https://jquery.com/
CSS (Cascading Style Sheets) is a formal language for describing the appearance of a document written using a markup language.
It is mainly used as a means of describing, decorating the appearance of web pages written using HTML and XHTML markup languages, but can also be applied to any XML documents, such as SVG or XUL.
https://www.w3.org/TR/CSS/#css
Bootstrap is not exclusively a CSS framework, but its most popular features are CSS-centric. These include a powerful grid, icons, buttons, map components, navigation bars, and more.
https://getbootstrap.com/
There are several libraries that do almost the same thing: add one or more animations to a specified element. The first such library to gain popularity in recent years was Dan Eden's Animate.css. This fun library contains dozens of built-in animations that shake, fade, slide, scale, and more.
https://animate.style/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.