简体   繁体   中英

How I can add data-icon attribute in select option using vue.js

UPD.

before modify

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

after modify

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

difference in require()

I have materializecss select When I addd in dataIcon url "http...." code is worked, but then I try add local file then nothing works. How do i specify the path to 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 is 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"
      }
    ]
  })

https://prnt.sc/tb3ept

files structure Empty image

You shoul keep all your static files in src/assets/ . For example if you wont use svg you can create folder with your svg files and after use some of file in your code or html template.

EDITED:

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"
  }
]
  })

You have very strange structure of folders. By default and recommended vue js documentation is something like this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM