The use of '-' in v-bind:style within Vue.js

I'm having trouble figuring out how to use CSS code with dashes in v-bind:style. When I attempt something like this:

<DIV style="width:100px;height: 100px;background-color: red;cursor: pointer;" v-bind:style="{ margin-left: margin + 'px'}"></DIV>

I receive the error message:

invalid expression: Unexpected token '-' in

Answer №1

According to the information in the documentation of Vue: "You have the option to use camelCase or kebab-case (with quotes) for CSS property names"

To correct this, you should modify the margin-left to either marginLeft OR 'margin-left' for it to function correctly.

Your revised code would look like this:

<div style="width:100px;height: 100px;background-color: red;cursor: pointer;" 
     v-bind:style="{ 'margin-left': margin + 'px'}">
     ...
</div>

OR

<div style="width:100px;height: 100px;background-color: red;cursor: pointer;" 
     v-bind:style="{ marginLeft: margin + 'px'}">
    ...
</div>

I trust this clarifies things!

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

Making a node.js API call using multipart/form-data

Submitting Data Using POST Node.js Data Capture Method without the Use of Express and Body-Parser FORM DATA: ORDERID: MID: TXNID: TXNAMOUNT: 5.00 PAYMENTMODE: NB CURRENCY: INR TXNDATE: 2021-06-14+23%3A02%3A30.0 STATUS: TXN_SUCCESS RESPCODE: 01 RESPMSG ...

Iterate through an array containing objects that may have optional properties, ensuring to loop through the entire

I need help iterating through an array of objects with a specific interface structure: export interface Incident { ID: string; userName1?: string; userName2?: string; userPhoneNumber?: string; crashSeverity: number; crashTime: number; } Here ...

Ways to prevent the use of the JavaScript increment (++) or decrement (--)

I have created two functions for a multi-step configuration on a webpage. protected clickNext(event:any, config:any) : any{ this.activeIndex++; } protected clickPrev(event:any, config:any) : any{ this.activeIndex--; } Here are the buttons: < ...

Verify the information received from the ajax call to PHP

After incorporating all the guidance I received, I performed an update and here are the results: UPDATED CODE: $(document).ready(function(){ $("#submit").submit(function(e){ e.preventDefault(); var username = $("#username").val(); var ...

What is the best way to duplicate all elements and their contents between two specified elements, and store them in a temporary

context = document.createElement("span"); start_element = my_start_element; end_element = my_end_element; // I need to find a way to iterate through a series of elements between start and end [start_element .. end_element].forEach(function(current_element ...

When making an Axios API request in Next.js, an error is encountered stating that the property 'map' cannot be read as it is undefined

Hey there! I've been trying to fetch data from the API endpoint in my NextJs application using axios. However, whenever I try to map over the retrieved data, NextJs keeps throwing the error message "TypeError: Cannot read property 'map' of ...

Utilizing JavaScript regex to remove substrings that contain parentheses

I am working with a string variable named myString that includes some unwanted content towards the end: var myString = 'The sentence is good up to here foo (bar1 bar2)'; var toBeRemoved = 'foo (bar1 bar2)'; I am looking for the best w ...

Exploring the contrast between an amd.js file and a main.js file within the dist directory of a JavaScript node project

Looking into a JavaScript project utilizing Node and Webpack, I've noticed that within the node_module directory there is a lib folder containing an xyz.js file. Additionally, in the dist folder of the node_module, there are xyz.amd.js, xyz.main.js, a ...

`Look up values from specified key names`

Consider the following JSON data: const information = { "item1":1, "item2":20, "item3":123, "item4":[{"a":"apple","b":"ball"}], "item5":1211 } In ...

Identify the difference between a regular function and a constructor in JavaScript

How can we determine whether a function in javascript is a simple, plain (anonymous) function, or a constructor (a function with a prototype)? I have developed the following function for this purpose: function checkFunctionType(value) { var ownPropert ...

Obtain the JSON data from the body of the current post request in Express.js

I have been working on retrieving the actual request body JSON in express.js but haven't been successful so far. Most of the resources I found online only show how to access the body of type ReqBody, whereas I am looking for a way to retrieve the actu ...

Using Radio Buttons in a jqGrid Interface

Currently, I am attempting to integrate radio buttons within a jqGrid framework. I am aware that a custom formatter can be utilized for this purpose. Below is my code snippet, however, it fails to provide information on which radio button is selected or if ...

What is the best way to incorporate a <li> view cap within a div element using JavaScript?

Currently, I am attempting to implement a dynamic <li> view limit within the content of a div. My goal is to display only 3 <li> elements each time the div content is scrolled. Although not confirmed, I believe this example may be helpful: ...

Modifying the display property of an element using JavaScript

Hello, I'm encountering an issue with a section of my javascript code. I am attempting to make the #showAddress element display as block when the deliverservice radio button is clicked or checked. I have tried searching for solutions on Stack Overflow ...

Authentication App for Android - Deliver renewed access token to VueJS

Hello, I am curious about the process that occurs after calling the performTokenRefresh method. public String performTokenRefresh() { final AuthState state = AuthUtils.readAuthState(context, key); final AuthorizationService service = new Au ...

Implementing a permanent class following an incident

Is it possible to dynamically add a class to an element when an event occurs rather than based on a condition? For example, I have a td that displays a variable. <td>{{myVar}}</td>//myVar=10 When the variable changes to myVar=15, I want to ad ...

What is the process of importing schema and resolvers in GraphQL-Yoga or Node?

After discovering that graphql-yoga V1 is no longer supported, I'm aiming to upgrade to graphql-yoga/node V2. Although I've reviewed the official documentation on the website, I'm encountering difficulties in migrating from V1 to V2. Is it ...

The Material UI Elements are not displaying properly as expected. Instead of seeing the MUI elements, a tan box is appearing. What steps can I take to resolve this

I'm currently using Material UI to build a basic header, footer, and profile page. However, whenever I attempt to display any type of element (such as Menu, Appbar, Toolbar, IconButton, Tab, Tabs, etc.), the page only shows a tan box instead of the a ...

Flow error: Unable to access the value of this.props.width as the property width is not defined in T

In my React Native project, I am utilizing Flow for type checking. For more information, visit: I currently have two files named SvgRenderer.js and Cartoon.js where: Cartoon extends SvgRenderer Below is the source code for both of these files: SvgRend ...

Fetching data in React using AJAX

I am in the process of developing a React Component that will display data retrieved from an AJAX call. Here's my scenario - I have a Jinja Flask back end hosted on AWS API Gateway, which requires custom headers and the Authorization header to serve H ...