Search code examples
cssvue.jsvue-componentvue-routerback-button

why browser's back button messes up my Vue component?


So I have a vue component (the first that I get to see in my app, it's called Intro.Vue) that looks like this: my Intro.vue component

When I click the orange button to go to another component everything seems OK. But when I press the browser's back button to return to my Intro.vue component, Everything messes up and it looks like this: Intro.vue after back button is clicked

Any idea of what might be happening here?

I'm using CSS grid to layout my app.

my code:

<template>
<div class="my-container">
    <div class="text1">{{frase_inicial}}</div>
    <div class="my-video">
        <div id="my-video">
            <h1>Video explicativo</h1>
        </div>
    </div>

    <div class="go-button">
        <router-link to="/crear">
        <img id="go-button" src="src/assets/comenzar-button.svg">
        </router-link>
    </div>

    <div class="text2">{{que_es}}</div>

    <div class="text3">{{expl_mixmatch}}</div>
</div>
</template>

<script>
export default {
  name:'intro',  
  data () {
    return {
    frase_inicial: '¿Quieres diseñar un peluche muy original?',
    que_es: '¿Qué es Mix&Match?',
    expl_mixmatch: 'Mix&Match es el juego que permite a los niños armar sus propios peluches Monomono y darles un nombre original que llevarán bordado. ¡Con imaginación, libertad y alegría!'
    }
  }
}
</script>

<style lang="scss">
@import url('https://fonts.googleapis.com/css?family=Raleway');
html{
    font-family: 'Raleway';
}

.my-container{
    display: grid;
    grid-template-columns: 100%;
    grid-template-rows: auto auto auto auto auto;
    grid-template-areas: "text1" "my-video" "go-button" "text2" "text3";

}

.text1{
    grid-area: text1;
    text-align: center;
    font-weight: bold;
    font-size: 3em;
    color: white;
    margin-top: 1em;
}
.my-video{
    grid-area: my-video;
    text-align: center;
    font-size: 2em;
    margin-top: 1em;
    display: grid;
    grid-template-columns: 100%;

}
#my-video{
   background: white;
   width: 640px;
   height: 480px;
   justify-self: center;
}

.go-button{
    grid-area: go-button;
    text-align: center;
    font-size: 2em;
    margin-top: 1em;
}

#go-button{
    height: 150px;
    width: 150px;
}

.text2{
    grid-area: text2;
    text-align: left;
    font-size: 2em;
    font-weight: bold;
    color: white;
    margin-top: 1em;
    margin-left: 1em;

}
.text3{
    grid-area: text3;
    text-align: left;
    font-size: 1.8em;
    margin-top: 1em; 
    color: white;
    margin-left: 1em;
    margin-bottom: 3em;
}

</style>

Solution

  • The problem was that I had an A.vue component with the same CSS class names than B.vue which was routed from A, and in A I wasn't declaring Scoped in it's styling, so it was using B style, which generated the stuff on screen to mess up.