[Vue2組件]三角形角標
< template> < div class = " ys-subscript" :style = " svgStyle" > < svg width = " 200" height = " 200" viewBox = " 0 0 200 200" xmlns = " http://www.w3.org/2000/svg" > < polygon points = " 0,0 200,0 200,200" :fill = " color" stroke = " none" /> < textx = " 133" y = " 67" text-anchor = " middle" dominant-baseline = " middle" :fill = " fontColor" font-family = " Arial, sans-serif" font-size = " 50" font-weight = " bold" transform = " rotate(45 133 67)" > {{ text }}</ text> </ svg> </ div>
</ template> < script>
export default { name: 'YsSubscript' , props: { text: { type: String, default : 'NEW' } , color: { type: String, default : '#67C23A' } , size: { type: [ String, Number] , default : '30px' } , fontColor: { type: String, default : '#ffffff' } , offsetY: { type: [ Number, String] , default : 0 } , offsetX: { type: [ Number, String] , default : 0 } } , computed: { svgStyle ( ) { const size = typeof this . size === 'number' ? ` ${ this . size} px ` : this . sizeconst offsetY = typeof this . offsetY === 'number' ? ` ${ this . offsetY} px ` : this . offsetYconst offsetX = typeof this . offsetX === 'number' ? ` ${ this . offsetX} px ` : this . offsetXreturn { width: size, height: size, top: offsetY, right: offsetX} } }
}
</ script> < style scoped >
.ys-subscript { position : absolute;
}
.ys-subscript svg { width : 100%; height : 100%;
}
</ style>