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