Discovering the method to incorporate a data-icon attribute within select options using vue.js

UPDATE

before modification

dataIcon: " @/images/flag-ukraine.svg"

after modification

dataIcon: require("@/assets/svg/flag-ukraine.svg"),

notable change with require()

I am using Materialize CSS select. When I use a URL for dataIcon like "http....", the code works fine. However, when I try to add a local file path, nothing seems to work. How can I specify the correct path for local files?

<div class="input-field col s12">
          <select ref="selectCategory" class="icons">
            <option
              v-for="lang in languages"
              :key="lang.id"
              :value="lang.langI"
              :data-icon="lang.dataIcon"
            >{{lang.lang}}</option>
          </select>
        </div>

this represents the data

data: () => ({
    date: new Date(),
    interval: null,
    dropdown: null,
    languages: [
      {
        lang: "Українська",
        langId: "uk-UA",
        dataIcon:
          " @/images/flag-ukraine.svg"
      },
      {
        lang: "English",
        langId: "en-US",
        dataIcon:
          "https://images.ua.prom.st/1440764527_saharnaya-kartinka-lyubov.jpg"
      }
    ]
  })

Screenshot link

File structure Empty image

Answer №1

It is advisable to store all your static files in the src/assets/ directory. For instance, if you do not plan to use SVG images, you can create a folder for your SVG files and then reference them in your code or HTML template.

UPDATED:

data: () => ({
date: new Date(),
interval: null,
dropdown: null,
languages: [
  {
    lang: "Українська",
    langId: "uk-UA",
    dataIcon: require("@/assets/svg/flag-ukraine.svg"),
  },
  {
    lang: "English",
    langId: "en-US",
    dataIcon:
      "https://images.ua.prom.st/1440764527_saharnaya-kartinka-lyubov.jpg"
  }
]
  })

Your folder structure seems unconventional. According to Vue.js documentation, it is recommended to follow a structure similar to this.

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

What is the best way to handle error messages on a Vue js 2 login form when the user inputs incorrect credentials?

Could someone please assist me in identifying where I made a mistake in handling errors when a user inputs incorrect login credentials? Any help would be greatly appreciated. I had to remove portions of my Firebase code as it was too long to upload here a ...

Guide to setting up routes in nuxt.js

I am building a blog website with Nuxt.Js on the domain xyz.com. I would like to display different pages based on country code, such as xyz.com/en/home and xyz.com/en/about. Can someone guide me on how to define routes in Nuxt.js for displaying blog conte ...

What is the best way to combine data from two rows into one row?

Can someone help me with merging 2 sets of Line data into a single row for each entry? For example, the 'Green Bay Packers @ Chicago Bears' row should display '+3.5000 and -3.5000', while 'Atlanta @ Minnesota' should show &apo ...

"Efficiently fetch data with an Express GET request without the

My goal is to send the client the HTML page (create.html) in response to a GET request triggered by a button click using fetch. I am intentionally avoiding the use of a form due to formatting and potential scalability issues. The code acknowledges that the ...

Initiating an AJAX request to a JSP file

Attempting to make an ajax call to a jsp page as shown below: $(document).ready(function () { $('#photo').photobooth().on("image", function (event, dataUrl) { alert(dataUrl); //alert($('#mygroupuserid')); ...

Creating an array of objects sorted in alphabetical order

My task involves working with an array of objects that each have a name property: var myList = [{ name: 'Apple' }, { name: 'Nervousness', }, { name: 'Dry' }, { name: 'Assign' }, { name: 'Date' }] ...

Using jQuery to retrieve the initial object in an array following an Ajax request

I need to retrieve the first object returned by an AJAX call before looping through it with the each() function. Here's the current code that successfully loops through the data: $.each(obj.DATA, function(indexInArray, value) { var depts ...

What is the best way to handle .jsx files in my library bundling process with Rollup?

Currently, I am in the process of developing a component library using storybook and rollup. Here is the configuration file rollup.config.mjs /* eslint-disable import/no-extraneous-dependencies */ import peerDepsExternal from 'rollup-plugin-peer-deps- ...

What is the proper way to execute this API request and retrieve the latest news data using the Fetch method?

Note: Please note that the API Key used in this code is not a real one for privacy reasons. const url = 'http://newsapi.org/v2/everything?' + 'q=platformer&' + 'apiKey=3ce15c4d1fd3485cbcf17879bab498db'; ...

Centralizing images in a Facebook gallery/lightbox during the loading process

Is the image width and height stored in Facebook's gallery database? In typical JavaScript usage, the image width and height cannot be determined until the image is fully loaded. However, on Facebook, images are pre-loaded before being displayed, ens ...

Implementing React and Material UI - Customizing Navigation Buttons/Links according to Routes

The following code snippet represents the main entry point of a React app, app.js, which includes the router endpoints. Below the app.js code, you will find the code for a Nav component, which serves as the navigation menu. I am looking to structure this ...

The current issue lies with the lack of functionality in the Ajax post feature

Seeking assistance here. I've encountered a frequent issue on stackoverflow and despite attempting various methods, none seem to be working for me. Could it be that I'm doing something fundamentally wrong? Here is the code snippet in question: $ ...

Update the browser URL dynamically without redirecting the page, by utilizing JavaScript after an AJAX call receives a

I am currently endeavoring to find a solution to replace the URL on my page without triggering a reload. My approach involves utilizing an infinite scroll JavaScript plugin. Upon receiving a response from an AJAX call, I intend to update the URL with the n ...

JavaScript tutorial: Removing spaces in column names and creating case-insensitive queries

This morning, I encountered an issue while working on a web app that I am currently developing. The app is designed to read data from an excel file and import it into a SQL table. During the basic validation process, I noticed that the column headers in ...

Display the retrieved information from MongoDB onto a jade template

Upon checking the console, I see output similar to this: [ { __v: 0, city: 'on1', address: '111', first: 'user', last: 'one', chart: 'char1', doctor: 'doc1', _id: 5698a803d98f05482ba48a4b }, { __ ...

Exploring Rails integration with FullCalendar: Retrieving data from the database using varying column titles

Currently utilizing Rails 4.0 in conjunction with FullCalendar, I am encountering an issue where some fields in my database do not align perfectly with the defaults of FullCalendar. For instance: My columns FullCalendar's Na ...

Can someone explain how I can effectively test the internal workings of a promise using Jasmine?

Within the Angular component I am testing, there is an async promise that I am struggling to examine. The code inside the 'then' block is crucial for my testing purposes, but I cannot seem to access it. angular.module('Ls', [ ]) funct ...

Utilize a Vue.js filter on the v-model within an input element

Seeking assistance! I successfully created a directive that wraps the Jasny Bootstrap Plugin, specifically focusing on the input mask feature! Additionally, I have developed a custom filter using moment to format date fields! The date format received fro ...

The keyboard fails to open when trying to input text on a WKWebView

Is there a way to programmatically open the keyboard in a WkWebView for tel text input after a JavaScript function call? I want the keyboard to display for efficiency reasons when a certain input is activated, but it doesn't gain focus automatically. ...

Testing an asynchronous generator function in Jest using unit tests

I need help writing a unit test for a generator function where I am struggling to properly mock a read stream object (ReadStream). Here is the function I'm trying to test: public async *readChunks(file: string, chunkSize: number): AsyncIterableIter ...