JavaScript Get value of Vue data model property based property name? data value model,key value data model,key value data

Let's say I have a div like below and my goal is to set it's css class to some computed string of classes based on the name of a vue data model property passed to the getClassText method:

 <div :class="getClassText('lastName')">

With this javascript:

 new Vue({
        el: '#app',
        data: {
            firstName: '',
            lastName: ''
        },
        methods: {
            getClassText: function (fieldName) {
                var valueOfField = NeedHelpHere(fieldName);
                //some complex calculations based on the valueOfFild
                return resultOfComplexCalculations;

            }
        }
    });

Inside the NeedHelpHere(fieldName) method I need to be able to return value of a Vue data model property based property name. How can that be done with Vue?

Note: I realize I could call the method without the quoting the lastName and that would cause the property's value to be passed in.

<div :class="getClassText(lastName)">

But for the sake of understanding Vue better, I'd like to know how to call the method passing the property name as a string like this

<div :class="getClassText('lastName')">

With such an approach, inside the NeedHelpHere(fieldName) method I need to be able to return value of a Vue data model property based property name. How can that be done with Vue?

Answer:1

I'm using Mapbox GL JS API to manipulate a Mapbox map. Right before I upload my result (which is a canvas.toDataURL) to the server through HTTP I need to resize my map (bigger resolution) and then use ...

I'm using Mapbox GL JS API to manipulate a Mapbox map. Right before I upload my result (which is a canvas.toDataURL) to the server through HTTP I need to resize my map (bigger resolution) and then use ...

  1. mapbox event on click
  2. mapbox on event

I'm trying to make something easy but, it doesn't work. I have this html <div class="positionDiv"> <img class="eyes" ng-model="showPasswordIsChecked" ng-click="afficherMdp()" ng-...

I'm trying to make something easy but, it doesn't work. I have this html <div class="positionDiv"> <img class="eyes" ng-model="showPasswordIsChecked" ng-click="afficherMdp()" ng-...

  1. ngmodelchange
  2. ngmodel angular
  3. ngmodeloptions
  4. ngmodeloptions u003d standalone true
  5. ngmodel checkbox
  6. ngmodel not working
  7. ngmodelgroup
  8. ngmodel radio button
  9. ngmodel select
  10. ngmodel on change
  11. ngmodel deprecated
  12. ngmodel vs formcontrol
  13. ngmodelchange debounce
  14. ngmodelchange not firing
  15. ngmodel change event
  16. ngmodel angularjs
  17. ngmodel two way binding
  18. ngmodel vs value
  19. ngmodel one way binding
  20. ngmodel pipe

I am very new to React, currently doing a small project of using GitHub API to return a search result via AJAX and be able to list that result on the screen. Currently I am using a for loop to iterate ...

I am very new to React, currently doing a small project of using GitHub API to return a search result via AJAX and be able to list that result on the screen. Currently I am using a for loop to iterate ...

  1. react setstate only if changed
  2. react setstate only one property
  3. react setstate only one property of object
  4. react setstate only part of state
  5. react setstate only if mounted
  6. react setstate change only one property
  7. react setstate update only one property
  8. react setstate only once

I'm working on a simple web form for teachers in my building to generate HTML pages with embedded videos to use locally (our substitutes can't get on the Internet to play videos; this is a workaround)....

I'm working on a simple web form for teachers in my building to generate HTML pages with embedded videos to use locally (our substitutes can't get on the Internet to play videos; this is a workaround)....

  1. iframe source from html
  2. source from folder html
  3. javascript source from html
  4. download source from html
  5. source html
  6. source html tag
  7. source html code
  8. source html element
  9. source html image
  10. source html online
  11. html5 source
  12. source html video
  13. source html viewer
  14. source html css
  15. source html chrome
  16. source html media
  17. source html picture
  18. source html img
  19. source html editor
  20. source html page