Vue CLI - include image from assets folder in static file

后端 未结 1 2043
抹茶落季
抹茶落季 2021-02-12 23:22

Is it possible to include an image, which is in assets/ foder, in some static .scss file, as a background-image?

I have a _b

相关标签:
1条回答
  • 2021-02-12 23:47

    You can manage that by :

    background-image: url('~@/assets/some_icon.svg');
    

    Key here is using ~@ as a prefix. URLs prefixed with ~ are treated as a module request. You need to use this prefix if you want to leverage Webpack's module resolving configurations. For example if you have a resolve alias for src folder equal to @, which you do if you use vue-cli3, you can use this type of URL to force Webpack to resolve to the needed asset in the assets folder. More info here: handling static assets

    0 讨论(0)
提交回复
热议问题