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