【问题标题】:Change Vue app background image for each route更改每条路线的 Vue 应用程序背景图像
【发布时间】:2020-09-03 09:39:54
【问题描述】:

我需要在我的应用程序的一些路由中添加背景图片,其他的留空

这是我的 app.vue:

<template>
  <div id="app">
    <div class="h-100">
      <div class="bg" >
        <NavBar/>
        <router-view></router-view>      
      </div>
    </div>
    <Footer/>
  </div>
</template>

要尝试在 / 中添加图像,请使用我的 Home.vue 的组件,如下所示:

<style >
.bg {
  height: 100%;
  background-image: url('../assets/equipo.jpg') !important;
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}
</style>

这会使该图像成为所有应用程序的背景,因此我尝试在其中一个我不希望这样的背景图像的组件中删除它:

<style >
 .bg {
   background-image: none;
 }
</style>

这会从所有应用程序路由中删除图像。我还尝试了第二个组件的范围样式,但不起作用。

我认为问题是: 如何从子的作用域样式中访问父元素?

【问题讨论】:

标签: javascript css vue.js background-image


【解决方案1】:

在您的组件上,您可以使用“作用域”样式:

<style scoped>
// your CSS here - this CSS will only affect the component and not propagate to other components.
</style>

【讨论】:

  • 这行不通,因为我要设置样式的元素是从他的父级包装作用域组件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-09-28
  • 2015-07-18
  • 1970-01-01
  • 2012-07-14
  • 1970-01-01
  • 1970-01-01
  • 2020-08-23
相关资源
最近更新 更多