Vue-组件CSS类未使用类样式绑定显示在应用中

时间:2020-03-25 21:08:14

标签: javascript html css vue.js

我是Vue的新手。我已经开始使用类样式的绑定语法。 我在CSS中定义的header和footer类没有显示,尽管在component标签中引用了它们。我似乎不知道为什么。

我尝试过将类放入组件中,但它们似乎也未显示在组件中。我感觉我必须以某种方式在Vue App初始化程序中绑定类?

谢谢!

App.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>

1 个答案:

答案 0 :(得分:0)

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

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

但这会:

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