[improvement] use component name (#2450)
This commit is contained in:
@@ -1,46 +1,18 @@
|
||||
/**
|
||||
* Create a basic component with common options
|
||||
*/
|
||||
import '../locale';
|
||||
import createBem from './bem';
|
||||
import useSfc from './use/sfc';
|
||||
import useBem from './use/bem';
|
||||
import i18n from '../mixins/i18n';
|
||||
import { isDef, camelize } from '.';
|
||||
|
||||
function install(Vue) {
|
||||
const { name } = this;
|
||||
Vue.component(name, this);
|
||||
Vue.component((camelize(`-${name}`)), this);
|
||||
}
|
||||
|
||||
function returnArray() {
|
||||
return [];
|
||||
}
|
||||
|
||||
function defaultProps(props) {
|
||||
Object.keys(props).forEach(key => {
|
||||
if (props[key] === Array) {
|
||||
props[key] = {
|
||||
type: Array,
|
||||
default: returnArray
|
||||
};
|
||||
} else if (props[key] === Number) {
|
||||
props[key] = {
|
||||
type: Number,
|
||||
default: 0
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
import { isDef } from '.';
|
||||
|
||||
export default function (sfc) {
|
||||
sfc.name = 'van-' + sfc.name;
|
||||
sfc.install = sfc.install || install;
|
||||
sfc = useSfc('van-' + sfc.name)(sfc);
|
||||
sfc.mixins = sfc.mixins || [];
|
||||
sfc.mixins.push(i18n);
|
||||
sfc.methods = sfc.methods || {};
|
||||
sfc.methods.isDef = isDef;
|
||||
sfc.methods.b = createBem(sfc.name);
|
||||
sfc.props && defaultProps(sfc.props);
|
||||
sfc.methods.b = useBem(sfc.name);
|
||||
|
||||
return sfc;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import Vue from 'vue';
|
||||
import use from './use';
|
||||
|
||||
const isServer = Vue.prototype.$isServer;
|
||||
|
||||
@@ -37,6 +38,7 @@ function range(num, min, max) {
|
||||
}
|
||||
|
||||
export {
|
||||
use,
|
||||
get,
|
||||
range,
|
||||
isObj,
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import useBem from './bem';
|
||||
import useSfc from './sfc';
|
||||
|
||||
export default function (name) {
|
||||
name = 'van-' + name;
|
||||
return [useSfc(name), useBem(name)];
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Create a basic component with common options
|
||||
*/
|
||||
import '../../locale';
|
||||
import { camelize } from '..';
|
||||
|
||||
const arrayProp = {
|
||||
type: Array,
|
||||
default: () => []
|
||||
};
|
||||
|
||||
const numberProp = {
|
||||
type: Number,
|
||||
default: 0
|
||||
};
|
||||
|
||||
function defaultProps(props) {
|
||||
Object.keys(props).forEach(key => {
|
||||
if (props[key] === Array) {
|
||||
props[key] = arrayProp;
|
||||
} else if (props[key] === Number) {
|
||||
props[key] = numberProp;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function install(Vue) {
|
||||
const { name } = this;
|
||||
Vue.component(name, this);
|
||||
Vue.component((camelize(`-${name}`)), this);
|
||||
}
|
||||
|
||||
export default name => sfc => {
|
||||
sfc.name = name;
|
||||
sfc.install = install;
|
||||
sfc.props && defaultProps(sfc.props);
|
||||
|
||||
return sfc;
|
||||
};
|
||||
Reference in New Issue
Block a user