About the problem of dynamic splicing src image address of img in Vue

About the problem of dynamic splicing src image address of img in Vue

Let's take a look at the dynamic splicing of img in Vue: src picture address, the specific content is as follows:

Usage scenario: Match local image resources according to the image tag returned by the backend. For example: According to the k1 tag returned by the backend, the front end generates the image resource path assets/images/inventory/k1.png

<template>
    <div class="fl">
          <img :src="getImgUrl(gatherInfo.img1)" alt="">
          <img :src="getImgUrl(gatherInfo.img2)" alt="">
          <img :src="getImgUrl(gatherInfo.img3)" alt="">
     </div>
</template>
data(){
    return {
      gatherInfo:
        title: 'Inventory summary information',
        img1: 'k1',
        img2: 'k2',
        img3: 'k3',
      },
    }
}

In methods

//Get the image address getImgUrl (img) {
      return require("@/assets/images/inventory/" + img+ ".png");
    },

This is the end of this article about dynamic splicing of img in Vue: src image address. For more relevant vue img dynamic splicing content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue render function dynamically loads img's src path operation
  • Use vue to dynamically splice urls through variables
  • Some experience on dynamic splicing of vue src path

<<:  How to configure MySQL8 in Nacos

>>:  How to install tomcat in docker and deploy the Springboot project war package

Recommend

Vue uses vue-quill-editor rich text editor and uploads pictures to the server

Table of contents 1. Preparation 2. Define the gl...

JavaScript macrotasks and microtasks

Macrotasks and Microtasks JavaScript is a single-...

Using better-scroll component in Vue to realize horizontal scrolling function

About Recently, in the process of learning Vue, I...

jQuery implements dynamic tag event

This article shares the specific code of jQuery t...

Detailed Explanation of JavaScript Framework Design Patterns

Table of contents mvc mvp mvvm The source of Vue ...

Detailed explanation of mysql trigger example

Table of contents What is a trigger Create a trig...

Detailed analysis of MySQL master-slave replication

Preface: In MySQL, the master-slave architecture ...

MySQL learning to create and operate databases and table DDL for beginners

Table of contents 1. Operate the database 1.1 Cre...

CSS 3.0 text hover jump special effects code

Here is a text hovering and jumping effect implem...

MySql COALESCE function usage code example

COALESCE is a function that refers to each parame...

Sharing of SVN service backup operation steps

SVN service backup steps 1. Prepare the source se...

HTML user registration page settings source code

Design the web page shown above: <!DOCTYPE htm...

Use Vue3+Vant component to implement App search history function (sample code)

I am currently developing a new app project. This...

Detailed explanation of mixed inheritance in Vue

Table of contents The effect of mixed inheritance...

Vue implements the countdown component for second kills

This article shares the specific code of Vue to i...