vue-custom-properties
Version:
Make easier to use CSS custom properties in Vue components
35 lines (34 loc) • 814 B
JavaScript
var Vue;
function install(Ctor) {
assert(!Vue, 'Already installed');
Vue = Ctor;
Vue.mixin({
mounted: init
});
}
function init() {
var _this = this;
var options = this.$options.customProperties || {};
Object.keys(options).forEach(function (key) {
var observer = options[key];
_this.$watch(observer, function (value) {
var style = _this.$el.style;
if (style) {
style.setProperty(key, value);
}
}, {
immediate: true
});
});
}
function assert(condition, message) {
if (!condition) {
throw new Error('[vue-custom-properties] ' + message);
}
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(install);
}
export default {
install: install
};