Created
January 23, 2018 03:04
-
-
Save edmondyip/eb9dd43377ce830a3b79cc6cb21c8d0e to your computer and use it in GitHub Desktop.
Convert Hex to RGB in Vue Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data: { | |
return { | |
opacity: 50 | |
} | |
}, | |
methods: { | |
convertHex: function (color) { | |
color = color.replace('#', '') | |
let r = parseInt(color.substring(0, 2), 16) | |
let g = parseInt(color.substring(2, 4), 16) | |
let b = parseInt(color.substring(4, 6), 16) | |
let result = 'rgba(' + r + ',' + g + ',' + b + ',' + this.opacity / 100 + ')' | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some refactoring changes