VueJS: Dynamic Class Binding












0














Vue -V -- 3.0.5.



I have a component Cube.vue in which I'm trying to set a blue or green class to a child element dynamically.



I've created the component and have it imported into a specific page but I can't get the or to work correctly.



<template>
<div :class="$style.cubeInner">
<div class="cube" :class="{ 'cube--blue': isBlue ? 'cube--green': isGreen }">
<div v-for="side in cubeside" :class="side.class" :key="side.id"></div>
</div>
</figure>
</template>


And here is my export



export default {
data() {
return {
Cube: 'cube',
isBlue: Boolean,
isGreen: Boolean,
};
}
};


I import into another component and render it via <cube-hover></cube-hover>. My question is do I need to set a prop or a data() for isBlue to be true or false? I can't seem to target the child since the entire component is being imported.



Basically, I can't target that nested <div>, it just adds the class to the parent. And I want to add 'cube--blue' or 'cube--green' to specific pages.










share|improve this question



























    0














    Vue -V -- 3.0.5.



    I have a component Cube.vue in which I'm trying to set a blue or green class to a child element dynamically.



    I've created the component and have it imported into a specific page but I can't get the or to work correctly.



    <template>
    <div :class="$style.cubeInner">
    <div class="cube" :class="{ 'cube--blue': isBlue ? 'cube--green': isGreen }">
    <div v-for="side in cubeside" :class="side.class" :key="side.id"></div>
    </div>
    </figure>
    </template>


    And here is my export



    export default {
    data() {
    return {
    Cube: 'cube',
    isBlue: Boolean,
    isGreen: Boolean,
    };
    }
    };


    I import into another component and render it via <cube-hover></cube-hover>. My question is do I need to set a prop or a data() for isBlue to be true or false? I can't seem to target the child since the entire component is being imported.



    Basically, I can't target that nested <div>, it just adds the class to the parent. And I want to add 'cube--blue' or 'cube--green' to specific pages.










    share|improve this question

























      0












      0








      0







      Vue -V -- 3.0.5.



      I have a component Cube.vue in which I'm trying to set a blue or green class to a child element dynamically.



      I've created the component and have it imported into a specific page but I can't get the or to work correctly.



      <template>
      <div :class="$style.cubeInner">
      <div class="cube" :class="{ 'cube--blue': isBlue ? 'cube--green': isGreen }">
      <div v-for="side in cubeside" :class="side.class" :key="side.id"></div>
      </div>
      </figure>
      </template>


      And here is my export



      export default {
      data() {
      return {
      Cube: 'cube',
      isBlue: Boolean,
      isGreen: Boolean,
      };
      }
      };


      I import into another component and render it via <cube-hover></cube-hover>. My question is do I need to set a prop or a data() for isBlue to be true or false? I can't seem to target the child since the entire component is being imported.



      Basically, I can't target that nested <div>, it just adds the class to the parent. And I want to add 'cube--blue' or 'cube--green' to specific pages.










      share|improve this question













      Vue -V -- 3.0.5.



      I have a component Cube.vue in which I'm trying to set a blue or green class to a child element dynamically.



      I've created the component and have it imported into a specific page but I can't get the or to work correctly.



      <template>
      <div :class="$style.cubeInner">
      <div class="cube" :class="{ 'cube--blue': isBlue ? 'cube--green': isGreen }">
      <div v-for="side in cubeside" :class="side.class" :key="side.id"></div>
      </div>
      </figure>
      </template>


      And here is my export



      export default {
      data() {
      return {
      Cube: 'cube',
      isBlue: Boolean,
      isGreen: Boolean,
      };
      }
      };


      I import into another component and render it via <cube-hover></cube-hover>. My question is do I need to set a prop or a data() for isBlue to be true or false? I can't seem to target the child since the entire component is being imported.



      Basically, I can't target that nested <div>, it just adds the class to the parent. And I want to add 'cube--blue' or 'cube--green' to specific pages.







      javascript vue.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 13:59









      fencepencilfencepencil

      18617




      18617
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Put the boolean into a data field, and then the condition check into a computed function.



          ...updated to add context



          export default {
          data: () => {
          ...
          isBlue: Boolean,
          isGreen: Boolean,
          },
          computed:
          isBlue() {
          if (is it blue?) return true;
          return false;
          },
          isGreen() {
          if (is it green?) return true;
          return false;
          }
          }

          <template>
          ...
          <div class="cube" :class="{ isBlue ? 'cube--blue' : 'cube--green': isGreen }">
          <!-- I think this is where you went wrong: "'cube--blue': isBlue ? 'cube--green': isGreen" see note -->
          </template>


          note



          You have a "?" separating your classes which should either be a comma, or you are trying to do a ternary operation. Comma separation could possibly apply both at once and I suspect you don't want that. Or if you are trying to do conditional class assignment:



          Fix your ternary syntax:



          `condition ? value if true : value if false`


          you are missing the
          : value if false portion



          What you probably want is:



          `:class="isBlue ? 'cube--blue' : 'cube--green'"


          Lastly



          Now that I've written this out I sort of feel like I should recommend a different approach. Assuming that this cube is either green OR blue, but never both at the same time, you might want to combine the logic into a single step. Perhaps you want to use a conditional inside of a getColor function? This is particularly smart if you will ever have more than two colors. Then the fn just returns a color and you can interpolate that into your class name like:



          <div :class="`cube--${color}`"></i>





          share|improve this answer























          • I think I'm too dumb for this answer, I'm not sure which component those go in.
            – fencepencil
            Nov 23 '18 at 16:15










          • @fencepencil I added some context for you, and think I found the main issue. I hope this helps
            – Kraken
            Nov 23 '18 at 19:49



















          0














          I can't understand what do you mean by 'or'.



          By looking at your data just type:



          <div class="cube" :class="{ 'cube--blue': isBlue, 'cube--green': isGreen }">




          Update:
          Kraken meant to change you approach to:



          <div class="cube" :class="`cube--${getColor}`">


          and in your data just type:



          data() {
          return {
          color: 'blue',
          };
          },
          computed: {
          getColor() {
          return this.color;
          },
          },


          With this approach you prepare yourself for maybe more colors in the future. By just updating this.color.






          share|improve this answer























          • This works in the same component, but what about on another component, trying to set isBlue. It doesn't recognize there is anything there because it simply sees <cube-hover></cube-hover> which is the main component.
            – fencepencil
            Nov 23 '18 at 14:31










          • I don't get what trouble you have but maybe Try to send a class name to child by props. And in parent component just do the logic which classes you want.. Can you supply some more code? The best would be jsfiddle
            – Adam Orlov
            Nov 23 '18 at 15:19












          • Thanks for the assistance on this man, I'm pullin out my fruckin hair! jsfiddle.net/fencepencil/eywraw8t/473028
            – fencepencil
            Nov 23 '18 at 16:10










          • So jsfiddle doesn't allow import/export components but in vscode, I have everything separated. I have a Page.vue and a Cube.vue. In Page.vue I just add <cube-hover></cube-hover> but the actual dynamic style is beneath that, in a child element, like 3 divs below ... I don't know how to target that child and change the class on it for each PageX.vue.
            – fencepencil
            Nov 23 '18 at 16:13










          • I realize I could just create a BlueCube.vue and a GreenCube.vue but that just seems ridiculous lol
            – fencepencil
            Nov 23 '18 at 16:17











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448071%2fvuejs-dynamic-class-binding%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Put the boolean into a data field, and then the condition check into a computed function.



          ...updated to add context



          export default {
          data: () => {
          ...
          isBlue: Boolean,
          isGreen: Boolean,
          },
          computed:
          isBlue() {
          if (is it blue?) return true;
          return false;
          },
          isGreen() {
          if (is it green?) return true;
          return false;
          }
          }

          <template>
          ...
          <div class="cube" :class="{ isBlue ? 'cube--blue' : 'cube--green': isGreen }">
          <!-- I think this is where you went wrong: "'cube--blue': isBlue ? 'cube--green': isGreen" see note -->
          </template>


          note



          You have a "?" separating your classes which should either be a comma, or you are trying to do a ternary operation. Comma separation could possibly apply both at once and I suspect you don't want that. Or if you are trying to do conditional class assignment:



          Fix your ternary syntax:



          `condition ? value if true : value if false`


          you are missing the
          : value if false portion



          What you probably want is:



          `:class="isBlue ? 'cube--blue' : 'cube--green'"


          Lastly



          Now that I've written this out I sort of feel like I should recommend a different approach. Assuming that this cube is either green OR blue, but never both at the same time, you might want to combine the logic into a single step. Perhaps you want to use a conditional inside of a getColor function? This is particularly smart if you will ever have more than two colors. Then the fn just returns a color and you can interpolate that into your class name like:



          <div :class="`cube--${color}`"></i>





          share|improve this answer























          • I think I'm too dumb for this answer, I'm not sure which component those go in.
            – fencepencil
            Nov 23 '18 at 16:15










          • @fencepencil I added some context for you, and think I found the main issue. I hope this helps
            – Kraken
            Nov 23 '18 at 19:49
















          0














          Put the boolean into a data field, and then the condition check into a computed function.



          ...updated to add context



          export default {
          data: () => {
          ...
          isBlue: Boolean,
          isGreen: Boolean,
          },
          computed:
          isBlue() {
          if (is it blue?) return true;
          return false;
          },
          isGreen() {
          if (is it green?) return true;
          return false;
          }
          }

          <template>
          ...
          <div class="cube" :class="{ isBlue ? 'cube--blue' : 'cube--green': isGreen }">
          <!-- I think this is where you went wrong: "'cube--blue': isBlue ? 'cube--green': isGreen" see note -->
          </template>


          note



          You have a "?" separating your classes which should either be a comma, or you are trying to do a ternary operation. Comma separation could possibly apply both at once and I suspect you don't want that. Or if you are trying to do conditional class assignment:



          Fix your ternary syntax:



          `condition ? value if true : value if false`


          you are missing the
          : value if false portion



          What you probably want is:



          `:class="isBlue ? 'cube--blue' : 'cube--green'"


          Lastly



          Now that I've written this out I sort of feel like I should recommend a different approach. Assuming that this cube is either green OR blue, but never both at the same time, you might want to combine the logic into a single step. Perhaps you want to use a conditional inside of a getColor function? This is particularly smart if you will ever have more than two colors. Then the fn just returns a color and you can interpolate that into your class name like:



          <div :class="`cube--${color}`"></i>





          share|improve this answer























          • I think I'm too dumb for this answer, I'm not sure which component those go in.
            – fencepencil
            Nov 23 '18 at 16:15










          • @fencepencil I added some context for you, and think I found the main issue. I hope this helps
            – Kraken
            Nov 23 '18 at 19:49














          0












          0








          0






          Put the boolean into a data field, and then the condition check into a computed function.



          ...updated to add context



          export default {
          data: () => {
          ...
          isBlue: Boolean,
          isGreen: Boolean,
          },
          computed:
          isBlue() {
          if (is it blue?) return true;
          return false;
          },
          isGreen() {
          if (is it green?) return true;
          return false;
          }
          }

          <template>
          ...
          <div class="cube" :class="{ isBlue ? 'cube--blue' : 'cube--green': isGreen }">
          <!-- I think this is where you went wrong: "'cube--blue': isBlue ? 'cube--green': isGreen" see note -->
          </template>


          note



          You have a "?" separating your classes which should either be a comma, or you are trying to do a ternary operation. Comma separation could possibly apply both at once and I suspect you don't want that. Or if you are trying to do conditional class assignment:



          Fix your ternary syntax:



          `condition ? value if true : value if false`


          you are missing the
          : value if false portion



          What you probably want is:



          `:class="isBlue ? 'cube--blue' : 'cube--green'"


          Lastly



          Now that I've written this out I sort of feel like I should recommend a different approach. Assuming that this cube is either green OR blue, but never both at the same time, you might want to combine the logic into a single step. Perhaps you want to use a conditional inside of a getColor function? This is particularly smart if you will ever have more than two colors. Then the fn just returns a color and you can interpolate that into your class name like:



          <div :class="`cube--${color}`"></i>





          share|improve this answer














          Put the boolean into a data field, and then the condition check into a computed function.



          ...updated to add context



          export default {
          data: () => {
          ...
          isBlue: Boolean,
          isGreen: Boolean,
          },
          computed:
          isBlue() {
          if (is it blue?) return true;
          return false;
          },
          isGreen() {
          if (is it green?) return true;
          return false;
          }
          }

          <template>
          ...
          <div class="cube" :class="{ isBlue ? 'cube--blue' : 'cube--green': isGreen }">
          <!-- I think this is where you went wrong: "'cube--blue': isBlue ? 'cube--green': isGreen" see note -->
          </template>


          note



          You have a "?" separating your classes which should either be a comma, or you are trying to do a ternary operation. Comma separation could possibly apply both at once and I suspect you don't want that. Or if you are trying to do conditional class assignment:



          Fix your ternary syntax:



          `condition ? value if true : value if false`


          you are missing the
          : value if false portion



          What you probably want is:



          `:class="isBlue ? 'cube--blue' : 'cube--green'"


          Lastly



          Now that I've written this out I sort of feel like I should recommend a different approach. Assuming that this cube is either green OR blue, but never both at the same time, you might want to combine the logic into a single step. Perhaps you want to use a conditional inside of a getColor function? This is particularly smart if you will ever have more than two colors. Then the fn just returns a color and you can interpolate that into your class name like:



          <div :class="`cube--${color}`"></i>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '18 at 19:54

























          answered Nov 23 '18 at 14:04









          KrakenKraken

          8281228




          8281228












          • I think I'm too dumb for this answer, I'm not sure which component those go in.
            – fencepencil
            Nov 23 '18 at 16:15










          • @fencepencil I added some context for you, and think I found the main issue. I hope this helps
            – Kraken
            Nov 23 '18 at 19:49


















          • I think I'm too dumb for this answer, I'm not sure which component those go in.
            – fencepencil
            Nov 23 '18 at 16:15










          • @fencepencil I added some context for you, and think I found the main issue. I hope this helps
            – Kraken
            Nov 23 '18 at 19:49
















          I think I'm too dumb for this answer, I'm not sure which component those go in.
          – fencepencil
          Nov 23 '18 at 16:15




          I think I'm too dumb for this answer, I'm not sure which component those go in.
          – fencepencil
          Nov 23 '18 at 16:15












          @fencepencil I added some context for you, and think I found the main issue. I hope this helps
          – Kraken
          Nov 23 '18 at 19:49




          @fencepencil I added some context for you, and think I found the main issue. I hope this helps
          – Kraken
          Nov 23 '18 at 19:49













          0














          I can't understand what do you mean by 'or'.



          By looking at your data just type:



          <div class="cube" :class="{ 'cube--blue': isBlue, 'cube--green': isGreen }">




          Update:
          Kraken meant to change you approach to:



          <div class="cube" :class="`cube--${getColor}`">


          and in your data just type:



          data() {
          return {
          color: 'blue',
          };
          },
          computed: {
          getColor() {
          return this.color;
          },
          },


          With this approach you prepare yourself for maybe more colors in the future. By just updating this.color.






          share|improve this answer























          • This works in the same component, but what about on another component, trying to set isBlue. It doesn't recognize there is anything there because it simply sees <cube-hover></cube-hover> which is the main component.
            – fencepencil
            Nov 23 '18 at 14:31










          • I don't get what trouble you have but maybe Try to send a class name to child by props. And in parent component just do the logic which classes you want.. Can you supply some more code? The best would be jsfiddle
            – Adam Orlov
            Nov 23 '18 at 15:19












          • Thanks for the assistance on this man, I'm pullin out my fruckin hair! jsfiddle.net/fencepencil/eywraw8t/473028
            – fencepencil
            Nov 23 '18 at 16:10










          • So jsfiddle doesn't allow import/export components but in vscode, I have everything separated. I have a Page.vue and a Cube.vue. In Page.vue I just add <cube-hover></cube-hover> but the actual dynamic style is beneath that, in a child element, like 3 divs below ... I don't know how to target that child and change the class on it for each PageX.vue.
            – fencepencil
            Nov 23 '18 at 16:13










          • I realize I could just create a BlueCube.vue and a GreenCube.vue but that just seems ridiculous lol
            – fencepencil
            Nov 23 '18 at 16:17
















          0














          I can't understand what do you mean by 'or'.



          By looking at your data just type:



          <div class="cube" :class="{ 'cube--blue': isBlue, 'cube--green': isGreen }">




          Update:
          Kraken meant to change you approach to:



          <div class="cube" :class="`cube--${getColor}`">


          and in your data just type:



          data() {
          return {
          color: 'blue',
          };
          },
          computed: {
          getColor() {
          return this.color;
          },
          },


          With this approach you prepare yourself for maybe more colors in the future. By just updating this.color.






          share|improve this answer























          • This works in the same component, but what about on another component, trying to set isBlue. It doesn't recognize there is anything there because it simply sees <cube-hover></cube-hover> which is the main component.
            – fencepencil
            Nov 23 '18 at 14:31










          • I don't get what trouble you have but maybe Try to send a class name to child by props. And in parent component just do the logic which classes you want.. Can you supply some more code? The best would be jsfiddle
            – Adam Orlov
            Nov 23 '18 at 15:19












          • Thanks for the assistance on this man, I'm pullin out my fruckin hair! jsfiddle.net/fencepencil/eywraw8t/473028
            – fencepencil
            Nov 23 '18 at 16:10










          • So jsfiddle doesn't allow import/export components but in vscode, I have everything separated. I have a Page.vue and a Cube.vue. In Page.vue I just add <cube-hover></cube-hover> but the actual dynamic style is beneath that, in a child element, like 3 divs below ... I don't know how to target that child and change the class on it for each PageX.vue.
            – fencepencil
            Nov 23 '18 at 16:13










          • I realize I could just create a BlueCube.vue and a GreenCube.vue but that just seems ridiculous lol
            – fencepencil
            Nov 23 '18 at 16:17














          0












          0








          0






          I can't understand what do you mean by 'or'.



          By looking at your data just type:



          <div class="cube" :class="{ 'cube--blue': isBlue, 'cube--green': isGreen }">




          Update:
          Kraken meant to change you approach to:



          <div class="cube" :class="`cube--${getColor}`">


          and in your data just type:



          data() {
          return {
          color: 'blue',
          };
          },
          computed: {
          getColor() {
          return this.color;
          },
          },


          With this approach you prepare yourself for maybe more colors in the future. By just updating this.color.






          share|improve this answer














          I can't understand what do you mean by 'or'.



          By looking at your data just type:



          <div class="cube" :class="{ 'cube--blue': isBlue, 'cube--green': isGreen }">




          Update:
          Kraken meant to change you approach to:



          <div class="cube" :class="`cube--${getColor}`">


          and in your data just type:



          data() {
          return {
          color: 'blue',
          };
          },
          computed: {
          getColor() {
          return this.color;
          },
          },


          With this approach you prepare yourself for maybe more colors in the future. By just updating this.color.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 24 '18 at 21:47

























          answered Nov 23 '18 at 14:10









          Adam OrlovAdam Orlov

          205210




          205210












          • This works in the same component, but what about on another component, trying to set isBlue. It doesn't recognize there is anything there because it simply sees <cube-hover></cube-hover> which is the main component.
            – fencepencil
            Nov 23 '18 at 14:31










          • I don't get what trouble you have but maybe Try to send a class name to child by props. And in parent component just do the logic which classes you want.. Can you supply some more code? The best would be jsfiddle
            – Adam Orlov
            Nov 23 '18 at 15:19












          • Thanks for the assistance on this man, I'm pullin out my fruckin hair! jsfiddle.net/fencepencil/eywraw8t/473028
            – fencepencil
            Nov 23 '18 at 16:10










          • So jsfiddle doesn't allow import/export components but in vscode, I have everything separated. I have a Page.vue and a Cube.vue. In Page.vue I just add <cube-hover></cube-hover> but the actual dynamic style is beneath that, in a child element, like 3 divs below ... I don't know how to target that child and change the class on it for each PageX.vue.
            – fencepencil
            Nov 23 '18 at 16:13










          • I realize I could just create a BlueCube.vue and a GreenCube.vue but that just seems ridiculous lol
            – fencepencil
            Nov 23 '18 at 16:17


















          • This works in the same component, but what about on another component, trying to set isBlue. It doesn't recognize there is anything there because it simply sees <cube-hover></cube-hover> which is the main component.
            – fencepencil
            Nov 23 '18 at 14:31










          • I don't get what trouble you have but maybe Try to send a class name to child by props. And in parent component just do the logic which classes you want.. Can you supply some more code? The best would be jsfiddle
            – Adam Orlov
            Nov 23 '18 at 15:19












          • Thanks for the assistance on this man, I'm pullin out my fruckin hair! jsfiddle.net/fencepencil/eywraw8t/473028
            – fencepencil
            Nov 23 '18 at 16:10










          • So jsfiddle doesn't allow import/export components but in vscode, I have everything separated. I have a Page.vue and a Cube.vue. In Page.vue I just add <cube-hover></cube-hover> but the actual dynamic style is beneath that, in a child element, like 3 divs below ... I don't know how to target that child and change the class on it for each PageX.vue.
            – fencepencil
            Nov 23 '18 at 16:13










          • I realize I could just create a BlueCube.vue and a GreenCube.vue but that just seems ridiculous lol
            – fencepencil
            Nov 23 '18 at 16:17
















          This works in the same component, but what about on another component, trying to set isBlue. It doesn't recognize there is anything there because it simply sees <cube-hover></cube-hover> which is the main component.
          – fencepencil
          Nov 23 '18 at 14:31




          This works in the same component, but what about on another component, trying to set isBlue. It doesn't recognize there is anything there because it simply sees <cube-hover></cube-hover> which is the main component.
          – fencepencil
          Nov 23 '18 at 14:31












          I don't get what trouble you have but maybe Try to send a class name to child by props. And in parent component just do the logic which classes you want.. Can you supply some more code? The best would be jsfiddle
          – Adam Orlov
          Nov 23 '18 at 15:19






          I don't get what trouble you have but maybe Try to send a class name to child by props. And in parent component just do the logic which classes you want.. Can you supply some more code? The best would be jsfiddle
          – Adam Orlov
          Nov 23 '18 at 15:19














          Thanks for the assistance on this man, I'm pullin out my fruckin hair! jsfiddle.net/fencepencil/eywraw8t/473028
          – fencepencil
          Nov 23 '18 at 16:10




          Thanks for the assistance on this man, I'm pullin out my fruckin hair! jsfiddle.net/fencepencil/eywraw8t/473028
          – fencepencil
          Nov 23 '18 at 16:10












          So jsfiddle doesn't allow import/export components but in vscode, I have everything separated. I have a Page.vue and a Cube.vue. In Page.vue I just add <cube-hover></cube-hover> but the actual dynamic style is beneath that, in a child element, like 3 divs below ... I don't know how to target that child and change the class on it for each PageX.vue.
          – fencepencil
          Nov 23 '18 at 16:13




          So jsfiddle doesn't allow import/export components but in vscode, I have everything separated. I have a Page.vue and a Cube.vue. In Page.vue I just add <cube-hover></cube-hover> but the actual dynamic style is beneath that, in a child element, like 3 divs below ... I don't know how to target that child and change the class on it for each PageX.vue.
          – fencepencil
          Nov 23 '18 at 16:13












          I realize I could just create a BlueCube.vue and a GreenCube.vue but that just seems ridiculous lol
          – fencepencil
          Nov 23 '18 at 16:17




          I realize I could just create a BlueCube.vue and a GreenCube.vue but that just seems ridiculous lol
          – fencepencil
          Nov 23 '18 at 16:17


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53448071%2fvuejs-dynamic-class-binding%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks