vue 在样式中使用背景图片

4 篇文章 0 订阅

vue 在样式中使用背景图片

代码如下:

width: 100%;
height: 100vh;
background: url('~@/assets/404.png') no-repeat center;

~Less 的转义字符


补充 vue 常用的图片引入

  1. 直接在 html 中使用
 <img src="@/assets/404.png" alt="">
  1. 动态 src
    当路径的文件名需要拼接变量的时候,可使用 require() 引入
    在 template 的:src 或者 script 的data computed 中都可以进行 require 引入或拼接
<img :src="require('./assets/404.png')" alt=""> // 相对路径
<img :src="require('@/assets/404.png')" alt=""> // 使用路径别名
<img :src="require('./assets/'+ this.imgName)" alt=""> // 拼接路径
<img :src="img3" alt=""> // 动态路径

<script>
export default:{
    data(){
        return {
          imgName:'404.png',
          img3:require('./assets/404.png'),
        }
      },
}
</script>
// 编译后:
<img src="/assets/img/404.png" alt="">

  1. 在样式中使用
width: 100%;
height: 100vh;
background: url('~@/assets/404.png') no-repeat center;

~Less 的转义字符


参考

https://segmentfault.com/a/1190000019495695?utm_source=tag-newest

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_pengliang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值