Changing the style in VUE by simply entering its name

Trying to modify the style attribute of an object by entering a number or text details into the input field. Frustrated that it only allows changing part of the object and not the entire specification.

Seeking advice on how to replace the entire object specifying the style.

html

<div>
      <label>Type width</label>
      <input type="text" v-on:keydown.enter='defst($event.target.value)'>
      <div :style='stylename'>kkk</div>
    </div>

js

new Vue({
    el: '#exercise',
    data: {

      narrow:{
        backgroundColor:'lemonchiffon',
        width:150+'px'
      },
      medium:{
        backgroundColor:'yellow',
        width:250+'px'
      },
      large:{
        backgroundColor:'orange',
        width:350+'px'
      },
      xlarge:{
        backgroundColor:'red',
        width:500 +'px'
      },
      stylename:''

    },
    methods: {
      defst(x){
        console.log(x);
        this.stylename=x
      }
    }
  });

Appreciate any help in advance.

Answer №1

Revise this section:

  adjust(x){
    console.log(x);
    this.stylevalue=x
  }

turns into

  adjust(x){
    console.log(x);
    this.stylevalue=this[x]
  }

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

Verify that the length of all input fields is exactly 7 characters

My task involves checking the length of multiple input fields that share a common class. The goal is to verify that all fields have a length of 7. After attempting a solution, I encountered an issue where even if the length of all fields is indeed 7, the ...

AngularJS allows for setting the rate value using the jQuery Raty plugin

I am attempting to implement the jquery raty plugin for star rating using angularjs. To achieve this, I have created a custom directive as shown below: app.directive("ngStars", function() { return { restrict: 'A', ...

Merging two distinct arrays of objects in JavaScript can be achieved by utilizing various methods and

I have a challenge where I need to merge two arrays of objects in a nested way. var array1=[{ PersonalID: '11', qusetionNumber: '1', value: 'Something' }, { PersonalID: '12', qusetionNumber: '2& ...

Error encountered: SyntaxError - Missing semicolon before statement in AJAX call while processing JSON data

I am currently in the process of making a cross domain JSONP call utilizing this code snippet: jQuery.ajax({ async: true, url: 'http://mnews.hostoi.com/test.json', dataType: 'jsonp', method: "GET&quo ...

Personalize the close button on the modal

Utilizing the angular strap modal in my controller looked like this: $scope.modal = $modal({ scope: $scope, title: 'My Title', content: text, html: true, contentTemplate: 'views/partials/myTemplate.html', show: ...

Error encountered: `prisma.product.findMany()` function call is not valid when the application is deployed on V

After adding Prisma to my site, I encountered an error while trying to deploy it. Unfortunately, I am unsure how to resolve this issue. PrismaClientKnownRequestError: Invalid `prisma.product.findMany()` invocation: Raw query failed. Code: `unknown`. Messa ...

Unlocking Security: Safeguarding Various Routes with JSON Web Token

I'm trying to streamline my code. Currently, I have multiple routes that each go through the JSON web token verification process individually. router.route('/some-route').post((req, res) => { jwt.verify(req.body.token, secret, (err, de ...

Navigating from Laravel Jetstream to a Vue file using the Inertia route

I am in the process of setting up a route in Laravel Jetstream using Inertia. I want the route to be /bloglist. The Vue file can be found at /resources/js/Blog/BlogList.vue Here is the route code I am using: Route::inertia('/bloglist', 'Bl ...

Troubleshooting the jQueryRotate clicking problem

I have been using the jQueryRotate.js extension to rotate a small arrow element (mimicking the behavior seen in OS X Aqua filesystems). The documentation for this extension can be found here. $(document).ready(function() { var rot=$('#expand ...

Error: React 404 - Unable to make a POST request with

I am new to utilizing Axios and Node.js as a backend technology. I recently inherited some React code for a login page and I'm struggling to understand why I'm unable to send a POST request to the backend. Below is my .env file: REACT_APP_BACKEN ...

Transforming a unirest 'GET' call into an axios request

I am currently utilizing TheRundown API to access sports data. The example provided to me makes use of unirest, but I am endeavoring to adapt that example into an axios request. While I have managed to make it work for the most part, my main challenge lies ...

What causes this loop to operate in one location but not in another?

import { log, logTitle } from "logger"; var persons = [ {name: "Alex", age:22}, {name: "Maria", age:30} ] var number = 0; for (var i = 0; i <= persons.length; i++) { log(persons[i].name); log(persons[i].age); l ...

Having trouble activating lazy loading on route level in Vue 2?

Recently, I've been experimenting with Vue.js and exploring its built-in lazy loading capabilities. However, it seems like my implementation may not be working as expected. Here's what I tried: I started a new project using Vue CLI 3 by running ...

Incorporating JavaScript into Tailored Widgets

This question pertains to Django: Best Way to Add Javascript to Custom Widgets However, this is a different scenario. The original inquiry focuses on incorporating javascript into a custom django widget using forms.Media, but that approach does not appl ...

Simple steps to duplicate an array in Typescript while also appending a new field to the duplicated array

I have an array of people. Each person object has fields for name and age. I want to create a new array by copying the original and adding a new field (country) to each person object. The country value will come from an array of strings. Therefore, the n ...

Troubleshooting: Why Your Angular Data Binding is Failing

I am integrating a WCF REST service with an AngularJS application. My goal is to retrieve account information based on the account number provided, however, I am encountering an issue where the text "Account_Type" is displayed three times before showing th ...

Troubleshooting issues with executeScript in Internet Explorer driver for Selenium

Unable to execute any JavaScript using "executescript" during functional tests in IE, while it works perfectly with Firefox. Despite hours of searching on Google, I haven't been able to find a solution. Here is an example of how I am trying to call i ...

What is the best method for iterating through a table's td tags in Laravel and Vue.js?

In the data below, I am attempting to loop through each Item in the table within the <td> tag so that two items are displayed in a single column. user >"name":"Bob" >"id":1 >"Item": >"name":"Desk" >"name":" ...

View a pink map on Openlayers 2 using an iPhone

I am currently working on a project where I am trying to track my location using my smartphone and display it on a map. To achieve this, I am utilizing openlayers 2. However, I am encountering an issue. When I implement the code below in a Chrome Browser ...

D3.js is providing inaccurate tick numbers

Even though I specify that I want 3 ticks, I end up with 4 in my d3 js code The y-axis values I am working with are [2, 1, 3, 2, 4, 4, 6] svg .select(`[data-labels-y]`) .call(d3.axisLeft().scale(yScale).ticks(3).tickPadding(4))` My expected tick valu ...