I'm curious if it's possible to dynamically access variables from Vue’s data collection by specifying the variable name through another variable. For instance, consider the following example:
Here are some of the variables/properties:
var siteAdminVue = new Vue({
el: "#siteAdmin",
data: {
tagtitle: "",
tagparent: "",
tagdesc: "",
badgestitle: "",
badgesdesc: "",
badgesprivilege: 0,
newstitle: "",
newsnotify: false,
newscontent: "",
}
Now, let’s say I want to set some of these properties in one of my Vue methods:
var self = this;
var type = currentSection.toString().substr(4);
var selectElement = document.getElementById(currentSection + "select");
// Name of the Vue property, such as newstitle
var titleElement = type + "title";
self.[titleElement]= selectElement.value;
Instead of using a switch statement to determine which property to set (newstitle, badgestitle, etc.), I am wondering if there is a way to store the property name in a variable and then use it to set the value. Is there a method to achieve this?
Thank you in advance!