简体   繁体   English

如何在 vue Js 中将道具传递给样式 object

[英]How do I pass prop to style object in vue Js

I'm trying to use an object to control the style of certain parts of an app as I'm trying to avoid inline styling.我试图使用 object 来控制应用程序某些部分的样式,因为我试图避免内联样式。 What how do I use Colour from props in the styling object below please?请问下面造型object中道具的Color怎么用?

 data: () => ({   
         props: ['header', 'questions', 'index', 'colour'],
         sectionScore: [],  
         styling: {
             borderLeft: '10px solid ${this.colour}'
         }         
     }),

I'm using the object in the main body with:style="styling".我在主体中使用 object with:style="styling"。

First the props option should be declared as a property outside the data option, second, define the styling property as a computed one:首先,应该将props选项声明为数据选项之外的属性,其次,将styling属性定义为计算属性:

props: ['header', 'questions', 'index', 'colour'],
data: () => ({   
         
         sectionScore: [],  
              
     }),

computed:{
   styling(){
     return {
             borderLeft: `10px solid ${this.colour}`
         }
  } 
}

I'm trying to use an object to control the style of certain parts of an app as I'm trying to avoid inline styling.我试图使用 object 来控制应用程序某些部分的样式,因为我试图避免内联样式。 What how do I use Colour from props in the styling object below please?请问如何在下面的样式 object 中使用来自道具的颜色?

 data: () => ({   
         props: ['header', 'questions', 'index', 'colour'],
         sectionScore: [],  
         styling: {
             borderLeft: '10px solid ${this.colour}'
         }         
     }),

I'm using the object in the main body with:style="styling".我在主体中使用 object:style="styling"。

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

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