vue-mixin-data-attributes
Advanced tools
Comparing version 1.0.2 to 1.0.3
33
index.js
@@ -1,32 +0,1 @@ | ||
module.exports = { | ||
mounted() { | ||
const attributes = this.getDataAttributes(); | ||
Object.assign(this, attributes); | ||
}, | ||
methods: { | ||
getDataAttributes() { | ||
if (!this.$el) { | ||
return {}; | ||
} | ||
if (this.$el.dataset) { | ||
return this.$el.dataset; | ||
} | ||
// http://stackoverflow.com/a/5915585/5930258 | ||
return Array.from(this.$el.attributes).reduce((memo, attr) => { | ||
if (/^data-/.test(attr.name)) { | ||
const key = attr.name | ||
.substr(5) | ||
.replace(/-(.)/g, ($0, $1) => $1.toUpperCase()); | ||
memo[key] = attr.value; | ||
} | ||
return memo; | ||
}, {}); | ||
}, | ||
}, | ||
}; | ||
module.exports = require('./dist').default; |
{ | ||
"name": "vue-mixin-data-attributes", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Reads `data-` attributes from the element and assigns them to the Vue instance/component.", | ||
"main": "index.js", | ||
"module": "index.es2015.js", | ||
"jsnext:main": "index.es2015.js", | ||
"scripts": { | ||
"test": "eslint index.js" | ||
"build": "babel lib -d dist", | ||
"test": "eslint lib" | ||
}, | ||
@@ -21,2 +24,4 @@ "keywords": [ | ||
"devDependencies": { | ||
"babel-cli": "^6.23.0", | ||
"babel-preset-es2015": "^6.22.0", | ||
"eslint": "^3.15.0", | ||
@@ -23,0 +28,0 @@ "eslint-config-vi": "^5.0.0" |
4172
11
65
4