[improvement] bem utils (#2443)

This commit is contained in:
neverland 2019-01-05 21:07:19 +08:00 committed by GitHub
parent de9c7ffe0a
commit 72c57663de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 18 deletions

View File

@ -22,24 +22,19 @@ const prefix = (name, mods) => {
}
const ret = {};
mods && Object.keys(mods).forEach(key => {
ret[name + MODS + key] = mods[key];
});
mods &&
Object.keys(mods).forEach(key => {
ret[name + MODS + key] = mods[key];
});
return ret;
};
export default {
methods: {
b(el, mods) {
const { name } = this.$options;
if (el && typeof el !== 'string') {
mods = el;
el = '';
}
el = join(name, el, ELEMENT);
return mods ? [el, prefix(el, mods)] : el;
}
export default name => (el, mods) => {
if (el && typeof el !== 'string') {
mods = el;
el = '';
}
el = join(name, el, ELEMENT);
return mods ? [el, prefix(el, mods)] : el;
};

View File

@ -2,7 +2,7 @@
* Create a basic component with common options
*/
import '../locale';
import bem from '../mixins/bem';
import createBem from './bem';
import i18n from '../mixins/i18n';
import { isDef, camelize } from '.';
@ -36,9 +36,10 @@ export default function (sfc) {
sfc.name = 'van-' + sfc.name;
sfc.install = sfc.install || install;
sfc.mixins = sfc.mixins || [];
sfc.mixins.push(i18n, bem);
sfc.mixins.push(i18n);
sfc.methods = sfc.methods || {};
sfc.methods.isDef = isDef;
sfc.methods.b = createBem(sfc.name);
sfc.props && defaultProps(sfc.props);
return sfc;