[bugfix] missing options (#624)

This commit is contained in:
neverland 2018-09-21 16:04:59 +08:00 committed by GitHub
parent 99360b0ef6
commit 265f609bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 467 additions and 512 deletions

32
dist/area/index.js vendored
View File

@ -1,7 +1,8 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
props: { props: {
title: String,
loading: Boolean,
value: { value: {
type: String, type: String,
observer(value) { observer(value) {
@ -9,8 +10,6 @@ VantComponent({
this.setValues(); this.setValues();
} }
}, },
title: String,
loading: Boolean,
itemHeight: { itemHeight: {
type: Number, type: Number,
value: 44 value: 44
@ -31,34 +30,29 @@ VantComponent({
} }
} }
}, },
data: { data: {
pickerValue: [0, 0, 0], pickerValue: [0, 0, 0],
columns: [] columns: []
}, },
computed: { computed: {
displayColumns() { displayColumns() {
const { columns = [], columnsNum } = this.data; const { columns = [], columnsNum } = this.data;
return columns.slice(0, +columnsNum); return columns.slice(0, +columnsNum);
} }
}, },
methods: { methods: {
onCancel() { onCancel() {
this.triggerEvent('cancel', { this.$emit('cancel', {
values: this.getValues(), values: this.getValues(),
indexs: this.getIndexs() indexs: this.getIndexs()
}); });
}, },
onConfirm() { onConfirm() {
this.triggerEvent('confirm', { this.$emit('confirm', {
values: this.getValues(), values: this.getValues(),
indexs: this.getIndexs() indexs: this.getIndexs()
}); });
}, },
onChange(event) { onChange(event) {
const { value } = event.detail; const { value } = event.detail;
const { pickerValue, displayColumns } = this.data; const { pickerValue, displayColumns } = this.data;
@ -67,65 +61,52 @@ VantComponent({
if (index < 0 || value[index] < 0) { if (index < 0 || value[index] < 0) {
return; return;
} }
const values = displayColumns[index]; const values = displayColumns[index];
this.code = values[value[index]].code; this.code = values[value[index]].code;
this.setValues(); this.setValues();
this.triggerEvent('change', { this.$emit('change', {
picker: this, picker: this,
values: this.getValues(), values: this.getValues(),
index index
}); });
}, },
getList(type, code) { getList(type, code) {
let result = []; let result = [];
if (type !== 'province' && !code) { if (type !== 'province' && !code) {
return result; return result;
} }
const list = this.data.areaList[`${type}_list`] || {}; const list = this.data.areaList[`${type}_list`] || {};
result = Object.keys(list).map(code => ({ result = Object.keys(list).map(code => ({
code, code,
name: list[code] name: list[code]
})); }));
if (code) { if (code) {
result = result.filter(item => item.code.indexOf(code) === 0); result = result.filter(item => item.code.indexOf(code) === 0);
} }
return result; return result;
}, },
getIndex(type, code) { getIndex(type, code) {
const compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6; const compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
const list = this.getList(type, code.slice(0, compareNum - 2)); const list = this.getList(type, code.slice(0, compareNum - 2));
code = code.slice(0, compareNum); code = code.slice(0, compareNum);
for (let i = 0; i < list.length; i++) { for (let i = 0; i < list.length; i++) {
if (list[i].code.slice(0, compareNum) === code) { if (list[i].code.slice(0, compareNum) === code) {
return i; return i;
} }
} }
return 0; return 0;
}, },
setValues() { setValues() {
let code = this.code || Object.keys(this.data.areaList.county_list)[0] || ''; let code = this.code || Object.keys(this.data.areaList.county_list)[0] || '';
const province = this.getList('province'); const province = this.getList('province');
const city = this.getList('city', code.slice(0, 2)); const city = this.getList('city', code.slice(0, 2));
this.setData({ this.setData({
'columns[0]': province, 'columns[0]': province,
'columns[1]': city 'columns[1]': city
}); });
if (city.length && code.slice(2, 4) === '00') { if (city.length && code.slice(2, 4) === '00') {
code = city[0].code; code = city[0].code;
} }
this.setData({ this.setData({
'columns[2]': this.getList('county', code.slice(0, 4)), 'columns[2]': this.getList('county', code.slice(0, 4)),
pickerValue: [ pickerValue: [
@ -135,17 +116,14 @@ VantComponent({
] ]
}); });
}, },
getValues() { getValues() {
const { displayColumns = [], pickerValue = [] } = this.data; const { displayColumns = [], pickerValue = [] } = this.data;
return displayColumns.map((option, index) => option[pickerValue[index]]); return displayColumns.map((option, index) => option[pickerValue[index]]);
}, },
getIndexs() { getIndexs() {
const { pickerValue, columnsNum } = this.data; const { pickerValue, columnsNum } = this.data;
return pickerValue.slice(0, columnsNum); return pickerValue.slice(0, columnsNum);
}, },
reset() { reset() {
this.code = ''; this.code = '';
this.setValues(); this.setValues();

2
dist/card/index.js vendored
View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: [ classes: [
'thumb-class', 'thumb-class',
@ -8,7 +7,6 @@ VantComponent({
'desc-class', 'desc-class',
'num-class' 'num-class'
], ],
props: { props: {
num: String, num: String,
desc: String, desc: String,

View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
props: { props: {
border: { border: {

5
dist/cell/index.js vendored
View File

@ -1,12 +1,10 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: [ classes: [
'title-class', 'title-class',
'label-class', 'label-class',
'value-class' 'value-class'
], ],
props: { props: {
title: null, title: null,
value: null, value: null,
@ -28,7 +26,6 @@ VantComponent({
value: true value: true
} }
}, },
computed: { computed: {
cellClass() { cellClass() {
const { data } = this; const { data } = this;
@ -39,13 +36,11 @@ VantComponent({
'van-cell--clickable': data.isLink || data.clickable 'van-cell--clickable': data.isLink || data.clickable
}); });
}, },
titleStyle() { titleStyle() {
const { titleWidth } = this.data; const { titleWidth } = this.data;
return titleWidth ? `max-width: ${titleWidth};min-width: ${titleWidth}` : ''; return titleWidth ? `max-width: ${titleWidth};min-width: ${titleWidth}` : '';
} }
}, },
methods: { methods: {
onClick() { onClick() {
const { url } = this.data; const { url } = this.data;

7
dist/col/index.js vendored
View File

@ -1,17 +1,17 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
relations: { relations: {
'../row/index': { '../row/index': {
type: 'ancestor' type: 'ancestor'
} }
}, },
props: { props: {
span: Number, span: Number,
offset: Number offset: Number
}, },
data: {
style: ''
},
computed: { computed: {
classes() { classes() {
const { span, offset } = this.data; const { span, offset } = this.data;
@ -21,7 +21,6 @@ VantComponent({
}); });
} }
}, },
methods: { methods: {
setGutter(gutter) { setGutter(gutter) {
const padding = `${gutter / 2}px`; const padding = `${gutter / 2}px`;

View File

@ -1,47 +1,39 @@
import { basic } from '../mixins/basic'; import { basic } from '../mixins/basic';
import { observe } from '../mixins/observer/index'; import { observe } from '../mixins/observer/index';
function mapKeys(source, target, map) {
Object.keys(map).forEach(key => {
target[map[key]] = source[key];
});
}
function VantComponent(sfc) { function VantComponent(sfc) {
const options = {}; const options = {};
// map props to properties mapKeys(sfc, options, {
if (sfc.props) { data: 'data',
options.properties = sfc.props; props: 'properties',
} mixins: 'behaviors',
// map mixins to behaviors methods: 'methods',
if (sfc.mixins) { beforeCreate: 'created',
options.behaviors = sfc.mixins; created: 'attached',
} mounted: 'ready',
// copy methods destroyed: 'detached',
if (sfc.methods) { relations: 'relations',
options.methods = sfc.methods; classes: 'externalClasses'
} });
if (sfc.beforeCreate) {
options.created = sfc.beforeCreate;
}
if (sfc.created) {
options.attached = sfc.created;
}
if (sfc.mounted) {
options.ready = sfc.mounted;
}
if (sfc.destroyed) {
options.detached = sfc.destroyed;
}
// map classes to externalClasses
options.externalClasses = sfc.classes || [];
// add default externalClasses // add default externalClasses
options.externalClasses = options.externalClasses || [];
options.externalClasses.push('custom-class'); options.externalClasses.push('custom-class');
// add default behaviors // add default behaviors
options.behaviors = sfc.mixins || []; options.behaviors = options.behaviors || [];
options.behaviors.push(basic); options.behaviors.push(basic);
// map field to form-field behavior
if (sfc.field) {
options.behaviors.push('wx://form-field');
}
// add default options // add default options
options.options = { options.options = {
multipleSlots: true, multipleSlots: true,
addGlobalClass: true addGlobalClass: true
}; };
// map field to form-field behavior
if (sfc.field) {
options.behaviors.push('wx://form-field');
}
observe(sfc, options); observe(sfc, options);
Component(options); Component(options);
} }

32
dist/dialog/dialog.js vendored
View File

@ -1,24 +1,16 @@
let queue = []; let queue = [];
const Dialog = options => { const Dialog = options => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const pages = getCurrentPages(); const pages = getCurrentPages();
const ctx = pages[pages.length - 1]; const ctx = pages[pages.length - 1];
const dialog = ctx.selectComponent(options.selector); const dialog = ctx.selectComponent(options.selector);
delete options.selector; delete options.selector;
if (dialog) { if (dialog) {
dialog.setData({ dialog.setData(Object.assign({ onCancel: reject, onConfirm: resolve }, options));
onCancel: reject,
onConfirm: resolve,
...options
});
queue.push(dialog); queue.push(dialog);
} }
}); });
}; };
Dialog.defaultOptions = { Dialog.defaultOptions = {
show: true, show: true,
title: '', title: '',
@ -34,35 +26,19 @@ Dialog.defaultOptions = {
closeOnClickOverlay: false, closeOnClickOverlay: false,
confirmButtonOpenType: '' confirmButtonOpenType: ''
}; };
Dialog.alert = options => Dialog(Object.assign({}, Dialog.currentOptions, options));
Dialog.alert = options => Dialog.confirm = options => Dialog(Object.assign({}, Dialog.currentOptions, { showCancelButton: true }, options));
Dialog({
...Dialog.currentOptions,
...options
});
Dialog.confirm = options =>
Dialog({
...Dialog.currentOptions,
showCancelButton: true,
...options
});
Dialog.close = () => { Dialog.close = () => {
queue.forEach(dialog => { queue.forEach(dialog => {
dialog.close(); dialog.close();
}); });
queue = []; queue = [];
}; };
Dialog.setDefaultOptions = options => { Dialog.setDefaultOptions = options => {
Object.assign(Dialog.currentOptions, options); Object.assign(Dialog.currentOptions, options);
}; };
Dialog.resetDefaultOptions = () => { Dialog.resetDefaultOptions = () => {
Dialog.currentOptions = { ...Dialog.defaultOptions }; Dialog.currentOptions = Object.assign({}, Dialog.defaultOptions);
}; };
Dialog.resetDefaultOptions(); Dialog.resetDefaultOptions();
export default Dialog; export default Dialog;

10
dist/dialog/index.js vendored
View File

@ -1,5 +1,4 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
props: { props: {
title: String, title: String,
@ -46,48 +45,39 @@ VantComponent({
value: false value: false
} }
}, },
data: { data: {
loading: { loading: {
confirm: false, confirm: false,
cancel: false cancel: false
} }
}, },
methods: { methods: {
onConfirm() { onConfirm() {
this.handleAction('confirm'); this.handleAction('confirm');
}, },
onCancel() { onCancel() {
this.handleAction('cancel'); this.handleAction('cancel');
}, },
onClickOverlay() { onClickOverlay() {
this.onClose('overlay'); this.onClose('overlay');
}, },
handleAction(action) { handleAction(action) {
if (this.data.asyncClose) { if (this.data.asyncClose) {
this.setData({ this.setData({
[`loading.${action}`]: true [`loading.${action}`]: true
}); });
} }
this.onClose(action); this.onClose(action);
}, },
close() { close() {
this.setData({ show: false }); this.setData({ show: false });
}, },
onClose(action) { onClose(action) {
if (!this.data.asyncClose) { if (!this.data.asyncClose) {
this.close(); this.close();
} }
this.$emit('close', action); this.$emit('close', action);
this.$emit(action); this.$emit(action);
const callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel']; const callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];
if (callback) { if (callback) {
callback(this); callback(this);

View File

@ -61,7 +61,7 @@ VantComponent({
timer: null timer: null
}, },
attached() { created() {
if (this.data.mode) { if (this.data.mode) {
this.setData({ this.setData({
hasRightIcon: true hasRightIcon: true
@ -69,7 +69,7 @@ VantComponent({
} }
}, },
detached() { destroyed() {
const { timer } = this.data; const { timer } = this.data;
timer && clearTimeout(timer); timer && clearTimeout(timer);
}, },

View File

@ -52,7 +52,7 @@ VantComponent({
progressWidth: 0 progressWidth: 0
}, },
ready() { mounted() {
this.setText(); this.setText();
this.setPivotStyle(); this.setPivotStyle();
this.getWidth(); this.getWidth();

2
dist/row/index.js vendored
View File

@ -20,7 +20,7 @@ VantComponent({
} }
}, },
ready() { mounted() {
if (this.data.gutter) { if (this.data.gutter) {
this.setGutter(); this.setGutter();
} }

View File

@ -28,7 +28,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.updateValue(this.data.value); this.updateValue(this.data.value);
}, },

View File

@ -31,7 +31,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.setData({ this.setData({
value: this.range(this.data.value) value: this.range(this.data.value)
}); });

2
dist/steps/index.js vendored
View File

@ -21,7 +21,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.formatSteps(); this.formatSteps();
}, },

View File

@ -20,7 +20,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.setData({ value: this.data.checked }); this.setData({ value: this.data.checked });
}, },

View File

@ -20,7 +20,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.setData({ value: this.data.checked }); this.setData({ value: this.data.checked });
}, },

View File

@ -24,7 +24,7 @@ VantComponent({
currentActive: -1 currentActive: -1
}, },
attached() { created() {
this.setData({ currentActive: this.data.active }); this.setData({ currentActive: this.data.active });
}, },

2
dist/tabs/index.js vendored
View File

@ -67,7 +67,7 @@ VantComponent({
scrollLeft: 0 scrollLeft: 0
}, },
ready() { mounted() {
this.setLine(); this.setLine();
this.scrollIntoView(); this.scrollIntoView();
}, },

View File

@ -1,7 +1,14 @@
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
type AreaItem = {
name: string;
code: string;
};
VantComponent({ VantComponent({
props: { props: {
title: String,
loading: Boolean,
value: { value: {
type: String, type: String,
observer(value) { observer(value) {
@ -9,8 +16,6 @@ VantComponent({
this.setValues(); this.setValues();
} }
}, },
title: String,
loading: Boolean,
itemHeight: { itemHeight: {
type: Number, type: Number,
value: 44 value: 44
@ -46,20 +51,20 @@ VantComponent({
methods: { methods: {
onCancel() { onCancel() {
this.triggerEvent('cancel', { this.$emit('cancel', {
values: this.getValues(), values: this.getValues(),
indexs: this.getIndexs() indexs: this.getIndexs()
}); });
}, },
onConfirm() { onConfirm() {
this.triggerEvent('confirm', { this.$emit('confirm', {
values: this.getValues(), values: this.getValues(),
indexs: this.getIndexs() indexs: this.getIndexs()
}); });
}, },
onChange(event) { onChange(event: Weapp.Event) {
const { value } = event.detail; const { value } = event.detail;
const { pickerValue, displayColumns } = this.data; const { pickerValue, displayColumns } = this.data;
const index = pickerValue.findIndex((item, index) => item !== value[index]); const index = pickerValue.findIndex((item, index) => item !== value[index]);
@ -72,14 +77,14 @@ VantComponent({
this.code = values[value[index]].code; this.code = values[value[index]].code;
this.setValues(); this.setValues();
this.triggerEvent('change', { this.$emit('change', {
picker: this, picker: this,
values: this.getValues(), values: this.getValues(),
index index
}); });
}, },
getList(type, code) { getList(type: string, code?: string): AreaItem[] {
let result = []; let result = [];
if (type !== 'province' && !code) { if (type !== 'province' && !code) {
return result; return result;
@ -98,7 +103,7 @@ VantComponent({
return result; return result;
}, },
getIndex(type, code) { getIndex(type: string, code: string): number {
const compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6; const compareNum = type === 'province' ? 2 : type === 'city' ? 4 : 6;
const list = this.getList(type, code.slice(0, compareNum - 2)); const list = this.getList(type, code.slice(0, compareNum - 2));
code = code.slice(0, compareNum); code = code.slice(0, compareNum);

View File

@ -30,7 +30,7 @@ VantComponent({
}, },
computed: { computed: {
cellClass() { cellClass(): string {
const { data } = this; const { data } = this;
return this.classNames('custom-class', 'van-cell', { return this.classNames('custom-class', 'van-cell', {
'van-hairline': data.border, 'van-hairline': data.border,
@ -40,7 +40,7 @@ VantComponent({
}); });
}, },
titleStyle() { titleStyle(): string {
const { titleWidth } = this.data; const { titleWidth } = this.data;
return titleWidth ? `max-width: ${titleWidth};min-width: ${titleWidth}` : ''; return titleWidth ? `max-width: ${titleWidth};min-width: ${titleWidth}` : '';
} }

View File

@ -12,8 +12,12 @@ VantComponent({
offset: Number offset: Number
}, },
data: {
style: ''
},
computed: { computed: {
classes() { classes(): string {
const { span, offset } = this.data; const { span, offset } = this.data;
return this.classNames('custom-class', 'van-col', { return this.classNames('custom-class', 'van-col', {
[`van-col--${span}`]: span, [`van-col--${span}`]: span,
@ -23,7 +27,7 @@ VantComponent({
}, },
methods: { methods: {
setGutter(gutter) { setGutter(gutter: number) {
const padding = `${gutter / 2}px`; const padding = `${gutter / 2}px`;
const style = gutter ? `padding-left: ${padding}; padding-right: ${padding};` : ''; const style = gutter ? `padding-left: ${padding}; padding-right: ${padding};` : '';
if (style !== this.data.style) { if (style !== this.data.style) {

View File

@ -5,6 +5,12 @@ import {
CombinedComponentInstance CombinedComponentInstance
} from '../../types/index'; } from '../../types/index';
function mapKeys(source: object, target: object, map: object) {
Object.keys(map).forEach(key => {
target[map[key]] = source[key];
});
}
function VantComponent<Data, Props, Methods, Computed>( function VantComponent<Data, Props, Methods, Computed>(
sfc: VantComponentOptions< sfc: VantComponentOptions<
Data, Data,
@ -16,58 +22,38 @@ function VantComponent<Data, Props, Methods, Computed>(
): void { ): void {
const options: any = {}; const options: any = {};
// map props to properties mapKeys(sfc, options, {
if (sfc.props) { data: 'data',
options.properties = sfc.props; props: 'properties',
} mixins: 'behaviors',
methods: 'methods',
// map mixins to behaviors beforeCreate: 'created',
if (sfc.mixins) { created: 'attached',
options.behaviors = sfc.mixins; mounted: 'ready',
} destroyed: 'detached',
relations: 'relations',
// copy methods classes: 'externalClasses'
if (sfc.methods) { });
options.methods = sfc.methods;
}
if (sfc.beforeCreate) {
options.created = sfc.beforeCreate;
}
if (sfc.created) {
options.attached = sfc.created;
}
if (sfc.mounted) {
options.ready = sfc.mounted;
}
if (sfc.destroyed) {
options.detached = sfc.destroyed;
}
// map classes to externalClasses
options.externalClasses = sfc.classes || [];
// add default externalClasses // add default externalClasses
options.externalClasses = options.externalClasses || [];
options.externalClasses.push('custom-class'); options.externalClasses.push('custom-class');
// add default behaviors // add default behaviors
options.behaviors = sfc.mixins || []; options.behaviors = options.behaviors || [];
options.behaviors.push(basic); options.behaviors.push(basic);
// map field to form-field behavior
if (sfc.field) {
options.behaviors.push('wx://form-field');
}
// add default options // add default options
options.options = { options.options = {
multipleSlots: true, multipleSlots: true,
addGlobalClass: true addGlobalClass: true
}; };
// map field to form-field behavior
if (sfc.field) {
options.behaviors.push('wx://form-field');
}
observe(sfc, options); observe(sfc, options);
Component(options); Component(options);
} }

View File

@ -1,6 +1,35 @@
let queue = []; let queue = [];
const Dialog = options => { type DialogAction = 'confirm' | 'cancel';
type DialogOptions = {
show?: boolean;
title?: string;
zIndex?: number;
message?: string;
overlay?: boolean;
selector?: string;
asyncClose?: boolean;
confirmButtonText?: string;
cancelButtonText?: string;
showConfirmButton?: boolean;
showCancelButton?: boolean;
closeOnClickOverlay?: boolean;
confirmButtonOpenType?: string;
}
interface Dialog {
(options: DialogOptions): Promise<DialogAction>;
alert?: (options: DialogOptions) => Promise<DialogAction>;
confirm?: (options: DialogOptions) => Promise<DialogAction>;
close?: () => void;
install?: () => void;
setDefaultOptions?: (options: DialogOptions) => void;
resetDefaultOptions?: () => void;
defaultOptions?: DialogOptions;
currentOptions?: DialogOptions;
}
const Dialog: Dialog = options => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const pages = getCurrentPages(); const pages = getCurrentPages();
const ctx = pages[pages.length - 1]; const ctx = pages[pages.length - 1];

View File

@ -61,7 +61,7 @@ VantComponent({
timer: null timer: null
}, },
attached() { created() {
if (this.data.mode) { if (this.data.mode) {
this.setData({ this.setData({
hasRightIcon: true hasRightIcon: true
@ -69,7 +69,7 @@ VantComponent({
} }
}, },
detached() { destroyed() {
const { timer } = this.data; const { timer } = this.data;
timer && clearTimeout(timer); timer && clearTimeout(timer);
}, },

View File

@ -52,7 +52,7 @@ VantComponent({
progressWidth: 0 progressWidth: 0
}, },
ready() { mounted() {
this.setText(); this.setText();
this.setPivotStyle(); this.setPivotStyle();
this.getWidth(); this.getWidth();

View File

@ -20,7 +20,7 @@ VantComponent({
} }
}, },
ready() { mounted() {
if (this.data.gutter) { if (this.data.gutter) {
this.setGutter(); this.setGutter();
} }

View File

@ -28,7 +28,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.updateValue(this.data.value); this.updateValue(this.data.value);
}, },

View File

@ -31,7 +31,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.setData({ this.setData({
value: this.range(this.data.value) value: this.range(this.data.value)
}); });

View File

@ -21,7 +21,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.formatSteps(); this.formatSteps();
}, },

View File

@ -20,7 +20,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.setData({ value: this.data.checked }); this.setData({ value: this.data.checked });
}, },

View File

@ -20,7 +20,7 @@ VantComponent({
} }
}, },
attached() { created() {
this.setData({ value: this.data.checked }); this.setData({ value: this.data.checked });
}, },

View File

@ -24,7 +24,7 @@ VantComponent({
currentActive: -1 currentActive: -1
}, },
attached() { created() {
this.setData({ currentActive: this.data.active }); this.setData({ currentActive: this.data.active });
}, },

View File

@ -67,7 +67,7 @@ VantComponent({
scrollLeft: 0 scrollLeft: 0
}, },
ready() { mounted() {
this.setLine(); this.setLine();
this.scrollIntoView(); this.scrollIntoView();
}, },

10
types/index.d.ts vendored
View File

@ -14,8 +14,8 @@ type Relations<Instance> = {
}; };
}; };
type RecordToAny<T> = { [K in keyof T]: any }; type RecordToAny<T> = { [K in keyof T]: any };
type Accessors<T> = { type RecordToReturn<T> = {
[K in keyof T]: (() => T[K]) [P in keyof T]: T[P] extends (...args: any[]) => any ? ReturnType<T[P]> : T[P]
} }
export type CombinedComponentInstance< export type CombinedComponentInstance<
@ -27,15 +27,15 @@ export type CombinedComponentInstance<
LooseObject & LooseObject &
Weapp.Component & Weapp.Component &
ComponentInstance & { ComponentInstance & {
data: Data & RecordToAny<Props> & Computed; data: Data & RecordToAny<Props> & RecordToReturn<Computed>;
}; };
export type VantComponentOptions<Data, Props, Methods, Computed, Instance> = { export type VantComponentOptions<Data, Props, Methods, Computed, Instance> = {
data?: Data; data?: Data;
props?: Props; props?: Props & ThisType<Instance>;
field?: boolean; field?: boolean;
mixins?: Mixins; mixins?: Mixins;
computed?: Accessors<Computed> & ThisType<Instance>; computed?: Computed & ThisType<Instance>;
relations?: Relations<Instance>; relations?: Relations<Instance>;
classes?: ExternalClasses; classes?: ExternalClasses;
methods?: Methods & ThisType<Instance>; methods?: Methods & ThisType<Instance>;

View File

@ -1,6 +1,7 @@
import { classNames } from './class-names'; import { classNames } from './class-names';
export interface ComponentInstance { export interface ComponentInstance {
triggerEvent: never;
$emit(name: string, detail?: any): void; $emit(name: string, detail?: any): void;
classNames: classNames; classNames: classNames;
} }

11
types/weapp.d.ts vendored
View File

@ -1,5 +1,11 @@
declare function Component(options: any): void; declare function Component(options: any): void;
interface wx {
[key: string]: any
}
declare const wx: wx;
declare namespace Weapp { declare namespace Weapp {
interface Component { interface Component {
getRelationNodes(selector: string): any[]; getRelationNodes(selector: string): any[];
@ -14,6 +20,7 @@ declare namespace Weapp {
interface Event { interface Event {
type: string; type: string;
detail: any;
timeStamp: number; timeStamp: number;
target: Target; target: Target;
currentTarget: Target; currentTarget: Target;
@ -31,8 +38,4 @@ declare namespace Weapp {
touches: Array<Touch>; touches: Array<Touch>;
changedTouches: Array<Touch>; changedTouches: Array<Touch>;
} }
interface CustomEvent extends Event {
detail: any;
}
} }