mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat: migrate Picker component
This commit is contained in:
parent
7e47a0721b
commit
9fa7a258d7
@ -43,4 +43,5 @@ module.exports = [
|
|||||||
'tab',
|
'tab',
|
||||||
'tabs',
|
'tabs',
|
||||||
'sticky',
|
'sticky',
|
||||||
|
'picker',
|
||||||
];
|
];
|
||||||
|
@ -43,6 +43,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emits: ['change'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
@ -266,28 +268,22 @@ export default createComponent({
|
|||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
style: optionStyle,
|
style: optionStyle,
|
||||||
attrs: {
|
role: 'button',
|
||||||
role: 'button',
|
tabindex: disabled ? -1 : 0,
|
||||||
tabindex: disabled ? -1 : 0,
|
|
||||||
},
|
|
||||||
class: [
|
class: [
|
||||||
bem('item', {
|
bem('item', {
|
||||||
disabled,
|
disabled,
|
||||||
selected: index === this.currentIndex,
|
selected: index === this.currentIndex,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
on: {
|
onClick: () => {
|
||||||
click: () => {
|
this.onClickItem(index);
|
||||||
this.onClickItem(index);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const childData = {
|
const childData = {
|
||||||
class: 'van-ellipsis',
|
class: 'van-ellipsis',
|
||||||
domProps: {
|
[this.allowHtml ? 'innerHTML' : 'textContent']: text,
|
||||||
[this.allowHtml ? 'innerHTML' : 'textContent']: text,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -62,14 +62,14 @@
|
|||||||
|
|
||||||
<demo-block card v-if="!isWeapp" :title="t('withPopup')">
|
<demo-block card v-if="!isWeapp" :title="t('withPopup')">
|
||||||
<van-field
|
<van-field
|
||||||
|
v-model="fieldValue"
|
||||||
readonly
|
readonly
|
||||||
clickable
|
clickable
|
||||||
:label="t('city')"
|
:label="t('city')"
|
||||||
:value="fieldValue"
|
|
||||||
:placeholder="t('chooseCity')"
|
:placeholder="t('chooseCity')"
|
||||||
@click="onClickField"
|
@click="onClickField"
|
||||||
/>
|
/>
|
||||||
<van-popup v-model="showPicker" round position="bottom">
|
<van-popup v-model:show="showPicker" round position="bottom">
|
||||||
<van-picker
|
<van-picker
|
||||||
show-toolbar
|
show-toolbar
|
||||||
:title="t('title')"
|
:title="t('title')"
|
||||||
|
@ -32,6 +32,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emits: ['confirm', 'cancel', 'change'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
children: [],
|
children: [],
|
||||||
@ -62,7 +64,9 @@ export default createComponent({
|
|||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
columns: {
|
columns: {
|
||||||
handler: 'format',
|
handler() {
|
||||||
|
this.format();
|
||||||
|
},
|
||||||
immediate: true,
|
immediate: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -261,10 +265,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
genTitle() {
|
genTitle() {
|
||||||
const titleSlot = this.slots('title');
|
if (this.$slots.title) {
|
||||||
|
return this.$slots.title();
|
||||||
if (titleSlot) {
|
|
||||||
return titleSlot;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.title) {
|
if (this.title) {
|
||||||
@ -276,19 +278,25 @@ export default createComponent({
|
|||||||
if (this.showToolbar) {
|
if (this.showToolbar) {
|
||||||
return (
|
return (
|
||||||
<div class={bem('toolbar')}>
|
<div class={bem('toolbar')}>
|
||||||
{this.slots() || [
|
{this.$slots.default
|
||||||
<button type="button" class={bem('cancel')} onClick={this.cancel}>
|
? this.$slots.default()
|
||||||
{this.cancelButtonText || t('cancel')}
|
: [
|
||||||
</button>,
|
<button
|
||||||
this.genTitle(),
|
type="button"
|
||||||
<button
|
class={bem('cancel')}
|
||||||
type="button"
|
onClick={this.cancel}
|
||||||
class={bem('confirm')}
|
>
|
||||||
onClick={this.confirm}
|
{this.cancelButtonText || t('cancel')}
|
||||||
>
|
</button>,
|
||||||
{this.confirmButtonText || t('confirm')}
|
this.genTitle(),
|
||||||
</button>,
|
<button
|
||||||
]}
|
type="button"
|
||||||
|
class={bem('confirm')}
|
||||||
|
onClick={this.confirm}
|
||||||
|
>
|
||||||
|
{this.confirmButtonText || t('confirm')}
|
||||||
|
</button>,
|
||||||
|
]}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -339,15 +347,15 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
render(h) {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div class={bem()}>
|
<div class={bem()}>
|
||||||
{this.toolbarPosition === 'top' ? this.genToolbar() : h()}
|
{this.toolbarPosition === 'top' ? this.genToolbar() : null}
|
||||||
{this.loading ? <Loading class={bem('loading')} /> : h()}
|
{this.loading ? <Loading class={bem('loading')} /> : null}
|
||||||
{this.slots('columns-top')}
|
{this.$slots['columns-top']?.()}
|
||||||
{this.genColumns()}
|
{this.genColumns()}
|
||||||
{this.slots('columns-bottom')}
|
{this.$slots['columns-bottom']?.()}
|
||||||
{this.toolbarPosition === 'bottom' ? this.genToolbar() : h()}
|
{this.toolbarPosition === 'bottom' ? this.genToolbar() : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -143,10 +143,10 @@ module.exports = {
|
|||||||
// path: 'password-input',
|
// path: 'password-input',
|
||||||
// title: 'PasswordInput 密码输入框',
|
// title: 'PasswordInput 密码输入框',
|
||||||
// },
|
// },
|
||||||
// {
|
{
|
||||||
// path: 'picker',
|
path: 'picker',
|
||||||
// title: 'Picker 选择器',
|
title: 'Picker 选择器',
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// path: 'radio',
|
// path: 'radio',
|
||||||
// title: 'Radio 单选框',
|
// title: 'Radio 单选框',
|
||||||
@ -477,10 +477,10 @@ module.exports = {
|
|||||||
// path: 'password-input',
|
// path: 'password-input',
|
||||||
// title: 'PasswordInput',
|
// title: 'PasswordInput',
|
||||||
// },
|
// },
|
||||||
// {
|
{
|
||||||
// path: 'picker',
|
path: 'picker',
|
||||||
// title: 'Picker',
|
title: 'Picker',
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// path: 'radio',
|
// path: 'radio',
|
||||||
// title: 'Radio',
|
// title: 'Radio',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user