[Improvement] Support Vue.use to register a component (#401)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Create a component with common options
|
||||
*/
|
||||
import '../locale';
|
||||
import Icon from '../icon';
|
||||
import i18n from '../mixins/i18n';
|
||||
import install from './install';
|
||||
import Loading from '../loading';
|
||||
|
||||
export default function(sfc) {
|
||||
sfc.mixins = sfc.mixins || [];
|
||||
sfc.components = sfc.components || {};
|
||||
sfc.install = sfc.install || install;
|
||||
sfc.mixins.push(i18n);
|
||||
sfc.components.icon = Icon;
|
||||
sfc.components.loading = Loading;
|
||||
|
||||
return sfc;
|
||||
};
|
||||
@@ -1,4 +1,6 @@
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
import { isDef } from './';
|
||||
|
||||
const { hasOwnProperty } = Object.prototype;
|
||||
|
||||
function isObj(x) {
|
||||
const type = typeof x;
|
||||
@@ -8,12 +10,7 @@ function isObj(x) {
|
||||
function assignKey(to, from, key) {
|
||||
const val = from[key];
|
||||
|
||||
if (
|
||||
val === undefined ||
|
||||
val === null ||
|
||||
(hasOwnProperty.call(to, key) &&
|
||||
(to[key] === undefined || to[key] === null))
|
||||
) {
|
||||
if (!isDef(val) || (hasOwnProperty.call(to, key) && !isDef(to[key]))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+15
-5
@@ -1,12 +1,13 @@
|
||||
import Vue from 'vue';
|
||||
import create from './create';
|
||||
|
||||
export const isServer = Vue.prototype.$isServer;
|
||||
const isServer = Vue.prototype.$isServer;
|
||||
|
||||
export function isDef(value) {
|
||||
function isDef(value) {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
|
||||
export function get(object, path) {
|
||||
function get(object, path) {
|
||||
const keys = path.split('.');
|
||||
let result = object;
|
||||
|
||||
@@ -18,11 +19,20 @@ export function get(object, path) {
|
||||
}
|
||||
|
||||
const camelizeRE = /-(\w)/g;
|
||||
export function camelize(str) {
|
||||
function camelize(str) {
|
||||
return str.replace(camelizeRE, (_, c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
export function isAndroid() {
|
||||
function isAndroid() {
|
||||
/* istanbul ignore next */
|
||||
return isServer ? false : /android/.test(navigator.userAgent.toLowerCase());
|
||||
}
|
||||
|
||||
export {
|
||||
get,
|
||||
isDef,
|
||||
create,
|
||||
isServer,
|
||||
camelize,
|
||||
isAndroid
|
||||
};
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* Install function to register a component
|
||||
*/
|
||||
export default function(Vue) {
|
||||
Vue.component(this.name, this);
|
||||
}
|
||||
Reference in New Issue
Block a user