Enhancing Vue with stylish components

My Vue component is quite basic, with the following structure:

<script>
export default {
props: {
source: {
type: String,
required: true,
}
},
}
</script>
<template>
  <div class="imageItem">
    <img class="image" :data-srcset="source" />
    <p> this is some text </p>
  </div>
</template>

One challenge I'm facing is customizing the component styles when loading it in the parent component like this:

<imageItem :source="source" />

I would like to have the ability to customize the component styles, for example by changing the text color:

<imageItem :source="source" :textColor="red" />

I've tried using props for this purpose but it's not working as expected. Can someone provide guidance on the correct approach to achieve this?

Answer №1

Give this a shot:

<script>
export default {
    props: {
        path: {
            type: String,
            required: true,
        },
        theme:{
            type: String,
            required:true
        }            
    },
}
</script>

<template>
  <div class="displayItem">
    <img class="image" :data-srcset="path" :style="theme" />
    <p> some sample text </p>
 </div>
</template>

Then in the property: "color:red"

<displayItem :path="path" :style="color : red" />

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

Exploring nested objects within Vue components

Is there a way to access the arrays of objects branches and report in the response when I only have access to currentView and subTask, but not subTasks2? I am following the same approach, but can't seem to access those specific elements. Any guidance ...

CSS: Centralize content and use a div to hide images that overflow the container

I successfully centered my divs and images both horizontally and vertically using CSS: .center { height: 100% } .center-center { position: absolute; top: 50%; left: 50%; width: 100%; transform: translate(-50%, -50%); text-align: center; ...

Avoiding overlapping handlers in VueJS

There seems to be an issue where a function is being called from mounted(), but when the elements are loaded, the same function is also called again, interrupting the first call and preventing it from completing the entire process. <b-table id=&qu ...

Difference between Vue 3.0 and the Breadcrumb error: Modifying the "items" property

I'm currently in the process of building a website with the vuesax theme and vue cli 3.0. Custom Default Layout: <template> <div class="main-wrapper"> <!---Navigation--> <Navbar :topbarCo ...

Issues with changing background colors using Jquery animate

I am attempting to create a fading background color effect when a button is clicked. Currently, I can change the background color using this code: $("#" + lblqty).css("background","#e9f1ff"); However, when I try to use the animate function as shown below ...

Learn the process of transferring data from a page to a layout in NUXT

I am in the process of creating a basic website. The goal is to dynamically change the Navbar elements based on the data set in the navLayout within the page template. My plan is to pass this data to the layout and then utilize props to transmit it to the ...

The transformation rotation applied in CSS must not have any impact on the styling of my span and paragraph

Snippet: .details-section{ background-color: rgb(83, 83, 83); height: 200px; } .icon-container{ border: 2px solid #c49b63; width: 90px; height: 90px; transition: 0.5s ease; } .box i{ font-size: 60px; color: black; margin-top: 13px ...

What causes my elements to move to the left when the screen size decreases with bootstrap?

If you want a better understanding of the situation, looking at images might be helpful. Here is how it typically appears: https://i.sstatic.net/mBZDp.jpg And this is how it appears on smaller screens: https://i.sstatic.net/8CuIs.jpg For smaller scree ...

Building an HTML table with predetermined measurements

Looking for Table Dimensions for A4 Print I am trying to create a table with specific dimensions for A4 print. The requirements are as follows: The first and last rows of the table must have a margin of 11 mm from the top and bottom edges of the paper Th ...

The auto setting in the CSS clamp function is not functioning properly when used as the minimum, value,

I have been trying to use the css function clamp() to control the height of my div, but for some reason it is not behaving as I expected. .container{ height: clamp(200px, auto, 400px); } Interestingly, it works perfectly fine when I define the heights ...

Is it possible to send cookies from Laravel to a different domain following an Ajax request?

Currently, I am delving into the world of Laravel passport package and embarking on creating a Single Page Application (SPA) using Vue.js to put it to the test. However, an issue has crossed my mind regarding saving the Token in the client browser. If I we ...

determining CSS selector

Having trouble identifying a locator using CSS. There are 10 elements with the same locator name on the webpage. Each web element has the same XPath value: //div[@class='thumb_image'] The web element list size is 10. If I want to access the 5t ...

What are the various ways to apply unique padding styles to ng-repeat items?

Take a look at this image. I need to position my 6 boxes on the 6 vertical lines above the image. I am struggling with applying different padding styles to my ng-repeat directive. Although I tried using [ng-class], it doesn't seem to work as expected. ...

The generated div from the Repeater Control is lacking appropriate CSS styling

I have a Repeater Control that is being used to generate div elements. While the DIV elements are successfully generated, the CSS formatting is not appearing correctly. Below is my HTML Code: <asp:Repeater ID="rptr" runat="server"> <Item ...

Getting two <div> elements to float below one another can be achieved by utilizing the CSS property "float

Can someone please tell me the trick to floating one element below another on the same side? I want them both to float but be positioned under each other. Thank you in advance. ...

What is the best way to adjust the height of a dropdown box in an angular application?

Is there a way to change the height of the scroll view? It seems too long for my liking, any advice? I attempted to adjust it using css but unfortunately, it didn't work out. The scroll view appears excessively lengthy as shown in the image below. h ...

What is causing the container to overlap with my sidebar-like <nav>?

Why is the fluid-container overlapping in this way, while others are not? Does this look correct to you, or am I overlooking something? It seems incorrect to me. <nav class="nav flex-column float-left"> {links} </nav> <div class="conta ...

How to disable the click handler of a div using only classes

Although I'm not an expert in HTML, I am eager to create a basic bootstrap button in HTML that can be enabled and disabled. My question relates to the following scenario: <div class="button" onClick=doSomething >My Button</div ...

Insert the GET object into an empty object within the data and then send it back

Here is the Vue application I am working with: new Vue({ name: 'o365-edit-modal-wrapper', el: '#o365-modal-edit-wrapper', data: function() { return { list: {}, } }, created() { thi ...

When a jQuery checkbox is checked, the addClass and toggleClass effects are applied to all DIVs, not just the enclosing DIV

I am working with Bootstrap Cards that have checkboxes inside them. When a checkbox is checked, I want to apply 2 specific classes to the Card DIVs: Change class="card border-secondary" to class="card border-success" Change class="card-header" to class ...