Trouble with retrieving the key-value pair of an object using V-html in Vuejs

I have a custom-preset.js file containing the following code. I am using this to obtain a dynamic value for the background color of a button.

var customPresets;
export default customPresets = color => (
    {
    "id": 0,
    "name": "custom",
    "html": `<button id='changecolor' style='color: rgb(255, 255, 255); background-color: ${color}; border-color: rgb(158, 50, 168);'>Accept</button>`
    }
)

I am trying to display the HTML returned from this JavaScript in a Vue file. Here is the code I have in the Vue file:

<b-form-radio-group>
   <b-form-radio v-for="customPreset in customPresets">
      <div v-html="customPreset.html"></div>  /// unable to print this
   </b-form-radio>
</b-form-radio-group>



import customPresets from './custom-preset';

 mounted () {
   console.log(customPresets);  /// I am able to get the output correctly
 }

https://i.sstatic.net/kpZJ5.png

Unfortunately, I cannot print console.log(customPresets.id) as it returns undefined. I am looking for a way to access the HTML (key-value pairs) in the Vue file.

Answer №1

Instead of using a loop, you can directly input a color name such as "green" into the customPresets() function. Then, you can access the value of the html property like this:

<b-form-radio>
   <div v-html="customPresets('green').html"></div>
</b-form-radio>

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

Executing Javascript requests on a php server hosted on the web

I'm facing a major issue in my application. I have an app that interacts with a PHP webservice and retrieves data upon button press. However, the service is unresponsive, and I'm struggling to identify the root cause. My intention is to send &ap ...

Encountered an unforeseen character 'u' in the initial position of the JSON while attempting to create a plugin

I seem to be encountering some issues with my code. Whenever I attempt to run the script in the developer kit, an error is thrown: unexpected token u in JSON at position 0... funciones.js $(document).ready(function (){ $("#btn1").click(funct ...

Blogger Extension - Cross Domain Communication

As I work on creating a blogger plugin, my goal is to send information from the blog page for analytic purposes and then display the results on the visitor's page. Initially, I tried sending the page content using an ajax call but encountered an error ...

Unlocking the potential of JSONSerialization key in Swift

Parse the JSON data below to return specific objects: { "id": "1000035148", "petId": "3", "ownerId": "1000", "locationId": null, "status": "Active", “services”: [ { "id": "5004", “data”: 1, “data1”: 0, “data2": 63, “data3”: 0 } ] } I&apo ...

Strange interaction observed when working with Record<string, unknown> compared to Record<string, any>

Recently, I came across this interesting function: function fn(param: Record<string, unknown>) { //... } x({ hello: "world" }); // Everything runs smoothly x(["hi"]); // Error -> Index signature for type 'string' i ...

Retrieving PHP data, utilizing the split method to break apart the commas within the string, and then displaying the information within a div using AJAX for a continuous refresh cycle every 3 seconds

I am attempting to extract data from a PHP string like '10,58,72,15,4,723,' and split it by commas into arrays using the split() method. My goal is to then place these arrays into different div elements and update the data every 3 seconds. Below ...

Transform jQuery code into vanilla JavaScript

I'm struggling with converting this part of code from jQuery to plain JavaScript. I've documented everything in a JSFiddle as an illustration. The following is the script: $(".button").click(function () { $pageID = $(this).attr('name& ...

Converting dates to time in amCharts v3: A step-by-step guide

I am looking to exclusively show "6 AM" on my X AXIS, rather than displaying 2019-09-05 06:00:00 Please refer to my code sample at https://jsfiddle.net/uwtz3p4h/ Is it feasible to only display the time? I have searched through their documentation but co ...

The suspense fallback function seems to be missing in NextJS 13

I'm in the process of creating an application to demonstrate the functionality of Suspense in Nextjs 13. However, I'm encountering an issue where the Suspense fallback is not appearing during loading. Below is the code for page.js import React, ...

express has a req.body that is devoid of any content

When making a request to my local server in my React app, the code looks like this: fetch("http://localhost:4000/signup", { method: "POST", mode: "no-cors", body: JSON.stringify({ name: "Joe", lname: "Doe& ...

Can you explain the concept of peer dependencies and plugins to me?

After reading numerous articles and posts on the topic of peer dependencies, I still find myself struggling to fully understand the concept. For instance, if coffee 1.0 has a dependency on milk 1.0, then logically coffee 1.0 would be included in my packa ...

Mastering the implementation of owl-carousel in React.js

I'm currently working on a project that involves utilizing the react framework. My intention is to incorporate the owl-carousel, however, I've encountered issues as it fails to function properly. The following error keeps popping up: OwlCarousel ...

Performing a Javascript validation to ensure that a value falls within

How can I check if an input number falls within a specified range? I need to display if it is within the range, higher, or lower than the acceptable range. My current Javascript code seems to be causing an error message stating it is an invalid entry. It ...

invoking a jquery method through the onClick event handler

How can I make use of jQuery to perform different actions based on which checkbox is clicked? I am encountering an issue where the onClick event is not triggered for any of the checkboxes below. <HTML> <HEAD> <script type="text/javascr ...

Unexpected token . encountered in Javascript: Uncaught Syntax Error. This error message is triggered when

As someone who is completely new to programming, I was given the task of creating a voting website for a class assignment. In order to store data locally, I managed to create variables and implement them using local storage: var eventName = document.getEl ...

Refreshing chord chart information from a JSON source in d3.js

I have two functions that are responsible for creating and drawing a D3 chord diagram representing the netflow between different IP addresses in our network. Function 1 (for creating the chord diagram) function createChords(jsonURL, containerID, tooltipI ...

Sending data from a React application to a Node.js server using Axios

Hello, I am facing an issue with an axios request to post data to a Node.js server. When trying to access this data on the server, it is showing as undefined. Below is the function for posting data: function Submit() { let params={ firstName: ...

Is there a way to configure the URL so that I can open my pdf object of Teamcenter Active Workspace (AWS) exclusively in the view window of the explorer browser through a link?

My organization's TC Active Workspace version is above 4.0 (AWS) and the URL link is structured like this: http://:Port/#/com.siemens.splm.clientfx.tcui.xrt.showObject?uid= . I am looking to specifically open a PDF in Browser View. The object I am re ...

Highchart won't load data from a PHP JSON request

Having trouble populating my Highchart with JSON data. The data shows up correctly on the webpage, but when using Highcharts, nothing happens. Once I remove the PHP and input static numbers, the chart generates successfully. In summary, Highcharts does n ...

Is there a way to access the history of Vue routers?

I am looking for a way to determine if the Vue router has additional entries in its history that can be navigated back to. This information is crucial for deciding whether or not to execute the exit app function. The app should only navigate back to prev ...