简体   繁体   English

如何使用 vue.js 在 select 选项中添加数据图标属性

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

UPD. UPD。

before modify修改前

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

after modify修改后

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

difference in require() 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.我有materializecss select 当我添加dataIcon url“http ....”代码时,但我尝试添加本地文件然后没有任何效果。 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 https://prnt.sc/tb3ept

files structure Empty image文件结构空图像

You shoul keep all your static files in src/assets/ .您应该将所有 static 文件保存在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.例如,如果您不使用 svg,您可以使用 svg 文件创建文件夹,然后在代码或 html 模板中使用一些文件。

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默认和推荐的 vue js 文档是这样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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