mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 18:00:27 +08:00
[improvement] bem utils (#2443)
This commit is contained in:
parent
de9c7ffe0a
commit
72c57663de
@ -22,17 +22,14 @@ const prefix = (name, mods) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ret = {};
|
const ret = {};
|
||||||
mods && Object.keys(mods).forEach(key => {
|
mods &&
|
||||||
|
Object.keys(mods).forEach(key => {
|
||||||
ret[name + MODS + key] = mods[key];
|
ret[name + MODS + key] = mods[key];
|
||||||
});
|
});
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default name => (el, mods) => {
|
||||||
methods: {
|
|
||||||
b(el, mods) {
|
|
||||||
const { name } = this.$options;
|
|
||||||
|
|
||||||
if (el && typeof el !== 'string') {
|
if (el && typeof el !== 'string') {
|
||||||
mods = el;
|
mods = el;
|
||||||
el = '';
|
el = '';
|
||||||
@ -40,6 +37,4 @@ export default {
|
|||||||
el = join(name, el, ELEMENT);
|
el = join(name, el, ELEMENT);
|
||||||
|
|
||||||
return mods ? [el, prefix(el, mods)] : el;
|
return mods ? [el, prefix(el, mods)] : el;
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
@ -2,7 +2,7 @@
|
|||||||
* Create a basic component with common options
|
* Create a basic component with common options
|
||||||
*/
|
*/
|
||||||
import '../locale';
|
import '../locale';
|
||||||
import bem from '../mixins/bem';
|
import createBem from './bem';
|
||||||
import i18n from '../mixins/i18n';
|
import i18n from '../mixins/i18n';
|
||||||
import { isDef, camelize } from '.';
|
import { isDef, camelize } from '.';
|
||||||
|
|
||||||
@ -36,9 +36,10 @@ export default function (sfc) {
|
|||||||
sfc.name = 'van-' + sfc.name;
|
sfc.name = 'van-' + sfc.name;
|
||||||
sfc.install = sfc.install || install;
|
sfc.install = sfc.install || install;
|
||||||
sfc.mixins = sfc.mixins || [];
|
sfc.mixins = sfc.mixins || [];
|
||||||
sfc.mixins.push(i18n, bem);
|
sfc.mixins.push(i18n);
|
||||||
sfc.methods = sfc.methods || {};
|
sfc.methods = sfc.methods || {};
|
||||||
sfc.methods.isDef = isDef;
|
sfc.methods.isDef = isDef;
|
||||||
|
sfc.methods.b = createBem(sfc.name);
|
||||||
sfc.props && defaultProps(sfc.props);
|
sfc.props && defaultProps(sfc.props);
|
||||||
|
|
||||||
return sfc;
|
return sfc;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user