Skip to content

Instantly share code, notes, and snippets.

@sioniks
Created March 17, 2020 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sioniks/3b77ca08c0a70f420c0e14d2f1e1d3f2 to your computer and use it in GitHub Desktop.
Save sioniks/3b77ca08c0a70f420c0e14d2f1e1d3f2 to your computer and use it in GitHub Desktop.
convert HEX to rgba Vue.js
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