简体   繁体   English

如何仅更改来自另一个组件的道具的颜色

[英]How do I change the color of only the props from another component

I want to change only the color of the string in 'subMsg'.我只想更改“subMsg”中字符串的颜色。 I don't want the color to affect the 'HomeContent' too.我不希望颜色也影响“HomeContent”。

<template>
  <div class="submit">
      <HomeContent v-bind:style="{ color: color }" subMsg="* Required"/>
       <div id="buttons">  
        <button type="button" class="btn btn-light"><router-link to="/about">Back</router-link></button>
        <button type="button" class="btn btn-primary" id="submit"><a href="#">Submit</a></button>
      </div>
  </div>
</template>

I alocated a different string to the same subMsg in another component but in this component.我在另一个组件中为同一个 subMsg 分配了一个不同的字符串,但在这个组件中。 I want the color to the different for only this subMsg component.我只希望这个 subMsg 组件的颜色不同。

import HomeContent from "@/components/HomeContent.vue";
export default {
 name: "Submit",
  components: {
    HomeContent
  },
  data() {
  return {
    color: "red"
  }
}
}

Is it possible to change the color?可以改变颜色吗?

you can do something like this:你可以这样做:

parent component:父组件:

//HTML part
<HomeContent :subMsg="{color:subMsgColor,message:'* Required'}"/>
// script part
data() {
  return {
    subMsgColor: "red"
  }

HomeContent component:主页内容组件:

<template>
  <div class="hello">
    <div class="card">
      <div class="card-content">
        <h1>{{ msg }}</h1>
        <p :style="{color:subMsg.color}">{{ subMsg.message }}</p>
      </div>
    </div>
  </div>
</template>

  <script>
    export default {
      name: "hello",
      data() {
        return {
          msg: "Data Collection"
        };
      },
      props: {
        subMsg: {
           type:Object,
           default:null
         }
      }
    } 
   </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM