mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-08-07 04:59:46 +08:00
[Improvement] optimize utils (#661)
This commit is contained in:
parent
39cdaf0907
commit
92b116c071
@ -128,10 +128,6 @@ module.exports = {
|
||||
path: '/progress',
|
||||
title: 'Progress - 进度条'
|
||||
},
|
||||
{
|
||||
path: '/search',
|
||||
title: 'Search - 搜索'
|
||||
},
|
||||
{
|
||||
path: '/stepper',
|
||||
title: 'Stepper - 步进器'
|
||||
@ -185,6 +181,10 @@ module.exports = {
|
||||
path: '/radio',
|
||||
title: 'Radio - 单选框'
|
||||
},
|
||||
{
|
||||
path: '/search',
|
||||
title: 'Search - 搜索'
|
||||
},
|
||||
{
|
||||
path: '/switch',
|
||||
title: 'Switch - 开关'
|
||||
@ -414,10 +414,6 @@ module.exports = {
|
||||
path: '/progress',
|
||||
title: 'Progress'
|
||||
},
|
||||
{
|
||||
path: '/search',
|
||||
title: 'Search'
|
||||
},
|
||||
{
|
||||
path: '/stepper',
|
||||
title: 'Stepper'
|
||||
@ -471,6 +467,10 @@ module.exports = {
|
||||
path: '/radio',
|
||||
title: 'Radio'
|
||||
},
|
||||
{
|
||||
path: '/search',
|
||||
title: 'Search'
|
||||
},
|
||||
{
|
||||
path: '/switch',
|
||||
title: 'Switch'
|
||||
|
@ -16,7 +16,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { create } from '../utils';
|
||||
import { create, isObj } from '../utils';
|
||||
import Picker from '../picker';
|
||||
|
||||
export default create({
|
||||
@ -42,7 +42,7 @@ export default create({
|
||||
|
||||
computed: {
|
||||
listValid() {
|
||||
return this.areaList && typeof this.areaList.province_list === 'object';
|
||||
return this.areaList && isObj(this.areaList.province_list);
|
||||
},
|
||||
|
||||
columns() {
|
||||
|
@ -25,7 +25,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { create } from '../utils';
|
||||
import { create, isObj } from '../utils';
|
||||
|
||||
const DEFAULT_DURATION = 200;
|
||||
const range = (num, arr) => Math.min(Math.max(num, arr[0]), arr[1]);
|
||||
@ -147,11 +147,11 @@ export default create({
|
||||
},
|
||||
|
||||
isDisabled(option) {
|
||||
return typeof option === 'object' && option.disabled;
|
||||
return isObj(option) && option.disabled;
|
||||
},
|
||||
|
||||
getOptionText(option) {
|
||||
return typeof option === 'object' && this.valueKey in option ? option[this.valueKey] : option;
|
||||
return isObj(option) && this.valueKey in option ? option[this.valueKey] : option;
|
||||
},
|
||||
|
||||
setIndex(index, userAction) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Vue from 'vue';
|
||||
import VueToast from './toast';
|
||||
import { isObj } from '../utils';
|
||||
|
||||
const defaultOptions = {
|
||||
type: 'text',
|
||||
@ -10,7 +11,7 @@ const defaultOptions = {
|
||||
position: 'middle',
|
||||
forbidClick: false
|
||||
};
|
||||
const parseOptions = message => typeof message === 'object' ? message : { message };
|
||||
const parseOptions = message => isObj(message) ? message : { message };
|
||||
|
||||
let queue = [];
|
||||
let singleton = true;
|
||||
|
@ -8,10 +8,10 @@ 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 = sfc.mixins || [];
|
||||
sfc.mixins.push(i18n);
|
||||
sfc.components = sfc.components || {};
|
||||
sfc.components.icon = Icon;
|
||||
sfc.components.loading = Loading;
|
||||
|
||||
|
@ -1,12 +1,7 @@
|
||||
import { isDef } from './';
|
||||
import { isDef, isObj } from './';
|
||||
|
||||
const { hasOwnProperty } = Object.prototype;
|
||||
|
||||
function isObj(x) {
|
||||
const type = typeof x;
|
||||
return x !== null && (type === 'object' || type === 'function');
|
||||
}
|
||||
|
||||
function assignKey(to, from, key) {
|
||||
const val = from[key];
|
||||
|
||||
|
@ -7,6 +7,11 @@ function isDef(value) {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
|
||||
function isObj(x) {
|
||||
const type = typeof x;
|
||||
return x !== null && (type === 'object' || type === 'function');
|
||||
}
|
||||
|
||||
function get(object, path) {
|
||||
const keys = path.split('.');
|
||||
let result = object;
|
||||
@ -30,6 +35,7 @@ function isAndroid() {
|
||||
|
||||
export {
|
||||
get,
|
||||
isObj,
|
||||
isDef,
|
||||
create,
|
||||
isServer,
|
||||
|
Loading…
x
Reference in New Issue
Block a user