Tips for adding background images when using nuxt generate

Apologies if this is evident

I'm in the process of generating thousands of pages using nuxt generate like so

<template>
    <div>
        <div class="main-picture">
           <span>{{landing.name}}<span>
        </div>
    </div>
<template>
<script>
import { landingshs } from '~/db/landingshs'
export default {
    data() {
        return {
            link: "https://upload.wikimedia.org/wikipedia/commons/4/4d/Cat_November_2010-1a.jpg"
        }
    },
    asyncData({ params }) {
    const landing = landingshs.find(l => l.id === params.id)
    
    return {landing}

 },

</script>

Now I am attempting to display an image like this

<style>
.main-picture {
    width: 1000px;
    height: 1000px;
    background-image: v-bind("`url(${link})`");
}
</style>

I have also tried another approach but with no luck. With this method, there isn't even a request in the network

 mounted() {
  setTimeout(() =>{
    document.querySelector('.main-picture').style.backgroundImage = "url(" + this.link + ")";
      }, 5000);
     
    },

Everything works well when creating a regular page (not _id.vue)

nuxt generate functions properly, inserts all necessary data

[email protected] [email protected]

Answer №1

attempt to utilize this method

 background-image: url({{link}});

if that doesn't work, try implementing this code in the template

:style="{ backgroundImage: `url(${link})` }"

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

Steps to reset default behavior after using event.preventDefault()

I came across a similar question on this post, but the solution provided did not work for my specific needs. So, I decided to share some example code and provide a bit of explanation... $(document).keypress( function (event) { // Pressing Up o ...

Is it a good idea to steer clear of including OAuth tokens in the

Utilizing my OAuth2 token in my API program is essential. However, I am also keen on sharing my code through GitHub. How can I securely use my confidential token without including it directly in my source code? ...

Avoid using single quotes in Postgres queries for a more secure Node.js application

Snippet from my node js code: var qry = 'INSERT INTO "sma"."RMD"("UserId","Favourite") VALUES (' + req.body.user + ',' + JSON.stringify(req.body.favourite) + ')' My problem is inserting single quotes before JSON.stringify(r ...

What is the best way to transform the incoming data using JavaScript?

The data I have from Algolia in my project includes a seconds data presented as an array. This is the method I use to extract the seconds data from Algolia: @if(isset($content['length'])) <div class="flex items-center space-x-6"> ...

Guide on moving a single item from one div to another

Here is a div that I need to modify: <div class="npwfu-inspiration"> <div class="npwfu-inspiration-inner"> <h1>Looking for inspiration?</h1> <p>Pick a category to see examples of what you can create with ...

What is the best way to disable a JavaScript code based on a specific screen width?

When I click on a specific link, it triggers an alert using jQuery. Here is the HTML code for the link: <a class="link" href="www.example.com">link</a> The JavaScript code attached to the link is as follows: $(".link").click(function() { ...

Ways to incorporate useEffect within a function or the other way around

Currently, I am facing an issue with my code. I have a function that handles the onChange event to retrieve the input value. Additionally, I have another function that searches for items in an array based on the value from the input and then renders a comp ...

Retrieve the variance between two arrays and store the additions in AddedList and the removals in RemovedList using typescript

I am still getting the hang of Typescript and I am trying to figure out the best solution for my issue. I have two arrays, A and B, and I need to identify the difference between them in relation to array A. The goal is to separate the elements that were ad ...

Tips for transferring the value from a Vue prompt to a JavaScript variable

I am currently implementing the Buefy UI Components and I need to pass the $(value) value outside of the function so that I can use it in an alert(thevalue) or something similar. I have scoured the internet for a solution but haven't been able to find ...

Sending Images from Vue to Node (Express) and Saving them in an AWS S3 Bucket: A Step-by-Step Guide

While working on a school management platform for my local school, everything was running smoothly until I encountered a particular issue. I needed to figure out how to send a selected image from the Vue front-end to the server so that the backend could re ...

Is it possible to use ng-click to pass multiple arrays at once?

I am working with a nested JSON object array and successfully displaying Inner Items grouped by Info in HTML using ng-repeat. Each Inner Item has a checkbox with an ng-click event handler that passes the selected Inner Items to the controller. However, I n ...

Retrieve a solitary row of information from a MySQL column

Here is an example of a MySQL database with the main table containing fields such as id, name, age, and photos: Table main: 3 John 22 photo1.jpg photo2.jpg photo3.jpg ph ...

Can TwitterBootstrap modal interrupt script execution?

I'm currently exploring how to implement a bootstrap modal on my webpage. My goal is to utilize ajax to submit a form, but before doing so, I'd like to prompt the user for additional input within the modal. After gathering this new input, I aim ...

Tips for automatically choosing several choices from a multiple-select using Chosen.JS

I am struggling to programmatically select multiple values in a multiple select using chosenJS/chosen.js while still ensuring that the selected values are bound to my ng-model (angularJS). In this scenario, I have a list of users, some of whom are already ...

Leveraging an HTML interface in conjunction with a node.js application

My objective is to implement JavaScript on the server side. To achieve this, I have decided to use node.js as it seems like the most logical solution. While I am quite familiar with node.js from working on applications, I now need to utilize it for server- ...

Clear out the existing elements in the array and replace them with fresh values

Within my Progressive Web App, I am utilizing HTTP requests to populate flip cards with responses. The content of the requests relies on the selected values. An issue arises when I choose an item from the dropdown menu. It triggers a request and displays ...

Discover Your Location in the Web Browser

My webpage includes the following JavaScript code to obtain the user's location: state.currentTimer = navigator.geolocation.watchPosition(success, error, { enableHighAccuracy: true, maximumAge: 5000 }); The page is designed to be accesse ...

Can the ngx-chips library be used to alter the language of chips?

Currently, I am working with the ngx-chips library and encountering a particular issue. Here is an image representation of the problem: https://i.sstatic.net/GL3Fd.png The challenge I am facing involves updating the language of the chips based on the sele ...

Using AngularJS: Implementing ng-include with a custom function

When using ng-include, I have encountered a peculiar issue. I am attempting to retrieve the template path by invoking a function defined in the controller that returns the path based on the parameter passed. Below is my code snippet: <tr ng-repeat="det ...

"When the focus is on, the DateTimePicker component in react widgets will automatically

Embarking on my journey with React, I have a reusable DateTime component defined as follows: interface IProps extends FieldRenderProps<Date, HTMLElement>, FormFieldProps {} const DateInput: React.FC<IProps> = ({ input, width, plac ...