简体   繁体   English

构建 Vuejs Tailwindcss 背景图片

[英]Build Vuejs Tailwindcss backgroundImage

When I'm building my VueJS app using CLI and tailwindcss, my backgroundImage part of tailwind.config.js doesn't work.当我使用 CLI 和 tailwindcss 构建我的 VueJS 应用程序时, tailwind.config.js的 backgroundImage 部分不起作用。

Here's my code:这是我的代码:

const plugin = require('tailwindcss/plugin')
module.exports = {
...
   backgroundImage: {
      'arrow_back': "url('./assets/img/arrow_back.svg')"
   }
...
}

My class bg-arrow_back isn't created when run npm run build I'm pretty sure it's because of the relative path, but when I'm reading the CLI doc, there are saying they handle it (and it does with npm run serve ).我的 class bg-arrow_back 不是在npm run serve npm run build时创建的)。

So if you have any idea of how to make it works?那么,如果您对如何使其工作有任何想法?

Thanks for help !感谢帮助 !

With vitejs and vue3 the config has to look like this:使用vitejsvue3的配置必须如下所示:

theme: {
extend: {
  backgroundImage: {
    'logo-test': "url('/src/assets/logo-test.svg')"
  }
},

In the Html use it like this:在 Html 中像这样使用它:

<div class="bg-logo-test"></div>

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

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