javascript - Vue - 使用类样式绑定(bind)的组件 CSS 类未显示在应用程序中

标签 javascript html css vue.js

我刚开始使用 Vue。我首先使用类样式绑定(bind)语法。 尽管在组件标签中引用了我在 CSS 中定义的页眉和页脚类,但它们并未显示。我似乎不明白为什么。

我尝试将这些类放入组件中,但它们似乎也没有显示在那里。我有一种感觉,我必须在 Vue 应用程序初始化程序中以某种方式绑定(bind)类?

提前致谢!

应用程序.vue

<template>
  <div id="app">
    <div class="container">
        <section>
          <LauchLogo class="header" />
          <LauchSymbol class="footer" />
        </section>
        <section>
          <LauchLogo class="header" />
          <LauchSymbol class="footer" />
        </section>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import LauchLogo from "./components/LauchLogo.vue";
import LauchSymbol from "./components/LauchSymbol.vue";

@Component({
  components: {
    LauchLogo,
    LauchSymbol
  }
})
export default class App extends Vue {
  data() {
    return {
      logo: 'logo',
      symbol: 'symbol'
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}
body {
  height: 100vh;
  overflow: hidden;
}
* {
  margin: 0;
  padding: 0;
}
.container {
  width: 100%;
  height: 100%;
  overflow-y: scroll;
  scroll-behavior: smooth;
  scroll-snap-type: y mandatory;
}
section {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-evenly;
  width: 100vw;
  height: 100vh;
  scroll-snap-align: center;
}
.footer {
  border: 2px green;
}
.header {
  border: 2px blue;
}
</style>

LauchSymbol.vue

<template>
  <div class="container">
      <img class="responsiveLauch alignMiddle bounce" src="../assets/JustLauch.png"/> 
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";

@Component
export default class HelloWorld extends Vue {
  //this is where you put your code

  // @Prop() private msg!: string;

  ScrollNext () {
    alert("hello");
  }
}



</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    .responsiveLauch {
        max-width: 5%;
        height: auto;
    }
    .bounce {
        animation: bounce 2s;
        /* animation-delay: 1s; */
        animation-iteration-count: infinite;
    }
    @keyframes bounce {
        0%,
        25%,
        50%,
        75%,
        100% {
           transform: translateY(0);
        }
        40% {
            transform: translateY(-80px);
        }
        60% {
            transform: translateY(-42px);
        }
    }
</style>

LauchLogo.vue

<template>
  <div class="container">
      <img class="responsiveLogo" src="../assets/LauchLogoTrimmed2.png"/> 
  </div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from "vue-property-decorator";

@Component
export default class HelloWorld extends Vue {
  //this is where you put your code

  // @Prop() private msg!: string;

  ScrollNext () {
    alert("hello");
  }
}



</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    .responsiveLogo {
        max-width: 55%;
        height: auto;
        padding-bottom: 300px;
    }
</style>

最佳答案

您可能只需要向 CSS 添加边框样式属性。您在此处添加的内容将显示边框:

.footer {
  border: 2px green;
}
.header {
  border: 2px blue;
}

但这会:

.footer {
  border: 2px solid green;
}
.header {
  border: 2px solid blue;
}

关于javascript - Vue - 使用类样式绑定(bind)的组件 CSS 类未显示在应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60857423/

相关文章:

javascript - 使用特定的kendo图表库文件而不是kendo.all.min.js

html - 动态居中 Fieldset 中的 Div/Text

internet-explorer - 适用于 IE 10+ 的模糊滤镜

javascript - 正则表达式:为什么我在结果中得到空字符串

html - 使用 flexbox 在链接中垂直对齐文本

python - 使用 pandas dataframe styler 正确的行着色

Javascript App Windows Universal - 脚本问题

javascript - 使用 Javascript 动态添加时,SVG 元素无法正确缩放

javascript - Bootstrap jsSocials PopOver

javascript - 在 Google Charts 函数中传入参数