Incorporate text onto images using VueJS

I am working on a swiper that displays images specified in an array. However, I need to include text within these images, and I'm struggling to find a solution for this. Does anyone have any insight on how to achieve this?

HTML

<template>
  <div>
    <div v-swiper:mySwiper="swiperOption" @someSwiperEvent="callback">
        <div class="swiper-wrapper">
            <div class="swiper-slide "   v-for="banner in banners" :key="banner">
              <img :src="getImage(banner)">
          </div>
        </div>
      </div>
    </div>
</template>

Javascript

 export default {
    data() {
      return {
         banners: [
           'Block1.png' , 'Block2.png' , 'Block3.png' ,'Block4.png'
         ] ,

         words :[
           'ABOUT AS' , 'WE OFFER' , 'OUR STAFF' , 'PORTFOLIO'
         ],

        swiperOption: {
          slidesPerView: 'auto',
          centeredSlides: true,
          spaceBetween: -400,
          pagination: {
            el: '.swiper-pagination',
            clickable: true
          }
        }
      }
    },
    methods : {
      getImage(src){
        return require(`~/assets/image/banners/${src}` )
      },
      callback (){

      },
      addWords(){

      },
    },
  }

Answer №1

Revamp your banners attribute by converting it into an array of objects rather than a simple array.

Each object within the array should include its own url and label:

...
    banners: [
        {img: "block1.png", label: 'my label'},
        {img: "block2.png", label: 'label 2'},
    ],

After making this change, you can easily retrieve the label for each banner in your loop:

<div class="swiper-wrapper">
    <div v-for="banner in banners" :key="banner" class="swiper-slide">
    <p>{{ banner.label }}</p>
    <img :src="getImage(banner.img)">
</div>

Another option is to follow Cathy Ha's suggestion from the comment above: utilize the loop index and call {{ words[index] }}.

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

Is it possible to operate a jQuery mobile web application while disconnected?

Recently, I've been experimenting with the idea of creating a web application using jQuery Mobile that involves utilizing forms such as checkboxes, text fields, and combo boxes. The tasks associated with this app are quite simple, but they require dat ...

Global Variables Evolution as Variables are Assigned

So I'm encountering an issue where running a function and assigning variables to the data seems to be updating my global every time. I've double-checked my code, but I can't seem to pinpoint where the update to the global is coming from. Am ...

The ngHide directive is only functional when used in conjunction with the ngRoute module, but unfortunately

Upon logging into my app, I want the login and signup buttons to disappear from the navigation bar. To achieve this, I am utilizing the ng-hide directive. This directive is triggered when the login is successful and a token is received from the server, whi ...

update embed - new command

My code below creates a slash command and I'm attempting to update the embed every 10 seconds. const embed = new EmbedBuilder() .setAuthor({ name: track.title, iconURL: client.user.displayAvatarURL({ size: 1024, dynamic: true }) }) .setThumbna ...

What is the process for removing a key from an object and replacing it with its corresponding value?

My JSON sample looks like this: var obj={ "results":{ "grade":"A", "marks":12 }, "data":{ "name":"sam", "gender":"male", "age":10 } }; I am trying to transform the above JSON to: var obj={ "res ...

Unable to establish a connection to localhost at port 3000 within the web application

I'm currently working on setting up a VueJS frontend with a Go-powered backend using gorilla/mux as the router. So far, everything seems to be functioning well. I have a static HTML file served through Go and Vue components bundled with webpack (webpa ...

How to access a nested child within a child in JSON using jQuery/JS?

I am curious to know if it is possible to loop through the nested elements in this JSON structure: [ { "name": "Hello", "views": 10, "subMovie": [ { "name": "World", "views": 10, "subMovie": [ { ...

The issue with Webpack chunking is that no content is appearing because the chunks are not

For the past day, I've been trying to resolve a frustrating yet seemingly simple problem. My goal is to split my bundle.js file into chunks to enhance website loading speed. Below is my webpack.config file: module.exports = { devServer: { historyApi ...

Choose an XPath selector that targets a list item within a specific div element

Currently, I am using selenium to conduct testing on a website. I have employed an XPath selector in order to locate a specific item within the HTML structure: <div id="boundlist-1051" class="x-boundlist list_cfg_cls x-boundlist-floating x-layer x-boun ...

What is the best way to capture any internal errors that may arise from external JavaScript code?

Within a JavaScript file, I am utilizing an API call (an npm module in Node.js) and aiming to gracefully handle any errors that may arise. However, if I input a faulty API-KEY or a non-existent city name, the internal code of the API generates an error tha ...

What is the best way to format 100K to appear as 100,000?

function formatNumberWithCommas(num) { return num >= 1000 ? `${Number.parseFloat((num).toFixed(3))}` : num; } ...

How can jQuery identify words of a certain length within a string?

Is there a more efficient way in jQuery to identify if a string contains words with a specified length or less? Rather than looping through each word individually as I planned, I'm wondering if there is a built-in function or easier approach available ...

Leveraging the power of ng-describe for comprehensive end-to-end testing using protractor

Recently, I stumbled upon a fantastic ng-describe package that simplifies the process of writing unit tests for AngularJS applications. It eliminates the need to remember and write all the boilerplate code required to load, inject, mock, or spy. Has anyon ...

Incorporating an HTML image into a div or table using jQuery

I am a beginner in using JQuery within Visual Studio 2013. My question is how to insert an img tag into a table or div using JQuery? For example, I have a div and I would like to generate an image dynamically using JQuery. Or, I have a dynamically create ...

"Exploring the Power of VueJS Classes and Conditions

Is it possible to add a Class based on a Child's Class Condition in the menu? For example: <ul :class="{ 'open' : ThereIsClassInChild }"> <li v-for="item in list" :class="{ 'active' : $route.name == item.routeName }" ...

Dynamic refresh of content with Ajax

Recently, I stumbled upon the platform Polyvore and decided to test it out. While experimenting with its "Create a set" feature, I noticed that the site provides a view of items either from your own collection or sourced elsewhere. An interesting observat ...

Tips on maintaining expanded rows in a table within Element UI

My table from element-ui is draggable: <table-card> <el-table-draggable @drop="changeDossiertypesOrder" handle=".handler"> <el-table :data="dossiertypes" v-loading="dossie ...

Can we send props to subcomponents in Inertia + Vue?

There are two components in my setup: Page.vue Component.vue In my Laravel route, I use: return inertia('Page', [ 'foo' => Model::all()->map(...) ]); Within Page.vue, I have the following code: <template> <Componen ...

Encountering an unknown symbol '''' while trying to import a JSX file into a JavaScript file in a React application

Looking for some help with my JSX file, here's a snippet: Selector.jsx import React, { Component } from 'react'; import FormControl from '@material-ui/core/FormControl'; import InputLabel from '@material-ui/core/InputLabel&a ...

What methods can be used for child components to communicate in React and React-Native?

Is there a way for child components in React to directly call functions from one another, such as accessing test1() from test2() or vice versa? I already have access to both functions from the parent components through ref_to_test1 and ref_to_test2. But ...