欢迎您访问新疆栾骏商贸有限公司,公司主营电子五金轴承产品批发业务!
全国咨询热线: 400-8878-609

新闻资讯

常见问题

vue template当中style背景设置不编译问题

作者:用户投稿2026-01-11 08:10:12
目录
  • template中style背景设置不编译
    • 解决方法
  • 如何给template组件加背景

    template中style背景设置不编译

    在vue定义的组件当中,直接设置行内style无法显示背景,里面使用config.resolve.alias当中设置的 @等路径符也无法识别

    <el-card style="backgroundImage:`url(`图片地址`)" class="box-card" shadow="hover">

    解决方法

    在将图片资源在vue 的 data当中解析再绑定到页面

    <el-card :style="{backgroundImage:`url(${img})`}" class="box-card" shadow="hover">
    // data当中定义 组件需要在函数当中返回数据 保证数据的作用域
    data: function(){
        return {
            weatherData:{},
            img: require('@assets/image/sunny_n.jpg')
        }
      },

    如何给template组件加背景

    <template>
      <div class="index_background" >
      </div>
    </template>
    <style>
    .index_background{ background: url('~@/../static/images/login-bg.png') center top no-repeat;}
    </style>

    以上为个人经验,希望能给大家一个参考,也希望大家多多支持。