mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[improvement] add link mixin (#750)
This commit is contained in:
parent
d0b1127802
commit
606c2896c1
@ -1,33 +1,32 @@
|
||||
import { link } from '../mixins/link';
|
||||
import { VantComponent } from '../common/component';
|
||||
|
||||
VantComponent({
|
||||
classes: [
|
||||
'num-class',
|
||||
'desc-class',
|
||||
'thumb-class',
|
||||
'title-class',
|
||||
'price-class',
|
||||
'origin-price-class',
|
||||
'desc-class',
|
||||
'num-class'
|
||||
],
|
||||
|
||||
mixins: [link],
|
||||
|
||||
props: {
|
||||
tag: String,
|
||||
num: String,
|
||||
desc: String,
|
||||
thumb: String,
|
||||
thumbMode: {
|
||||
type: String,
|
||||
value: 'scaleToFill'
|
||||
},
|
||||
title: String,
|
||||
price: String,
|
||||
originPrice: String,
|
||||
centered: Boolean,
|
||||
lazyLoad: Boolean,
|
||||
thumbLink: String,
|
||||
linkType: {
|
||||
originPrice: String,
|
||||
thumbMode: {
|
||||
type: String,
|
||||
value: 'navigateTo'
|
||||
value: 'scaleToFill'
|
||||
},
|
||||
currency: {
|
||||
type: String,
|
||||
@ -37,10 +36,7 @@ VantComponent({
|
||||
|
||||
methods: {
|
||||
onClickThumb() {
|
||||
const { thumbLink } = this.data;
|
||||
if (thumbLink) {
|
||||
wx[this.data.linkType]({ url: thumbLink });
|
||||
}
|
||||
this.jumpLink('thumbLink');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { link } from '../mixins/link';
|
||||
import { VantComponent } from '../common/component';
|
||||
|
||||
VantComponent({
|
||||
@ -7,10 +8,11 @@ VantComponent({
|
||||
'value-class'
|
||||
],
|
||||
|
||||
mixins: [link],
|
||||
|
||||
props: {
|
||||
title: null,
|
||||
value: null,
|
||||
url: String,
|
||||
icon: String,
|
||||
label: String,
|
||||
center: Boolean,
|
||||
@ -19,10 +21,6 @@ VantComponent({
|
||||
clickable: Boolean,
|
||||
titleWidth: String,
|
||||
customStyle: String,
|
||||
linkType: {
|
||||
type: String,
|
||||
value: 'navigateTo'
|
||||
},
|
||||
border: {
|
||||
type: Boolean,
|
||||
value: true
|
||||
@ -44,15 +42,5 @@ VantComponent({
|
||||
const { titleWidth } = this.data;
|
||||
return titleWidth ? `max-width: ${titleWidth};min-width: ${titleWidth}` : '';
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
onClick() {
|
||||
const { url } = this.data;
|
||||
if (url) {
|
||||
wx[this.data.linkType]({ url });
|
||||
}
|
||||
this.$emit('click');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
18
packages/mixins/link.ts
Normal file
18
packages/mixins/link.ts
Normal file
@ -0,0 +1,18 @@
|
||||
export const link = Behavior({
|
||||
properties: {
|
||||
url: String,
|
||||
linkType: {
|
||||
type: String,
|
||||
value: 'navigateTo'
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
jumpLink(urlKey = 'url') {
|
||||
const url = this.data[urlKey];
|
||||
if (url) {
|
||||
wx[this.data.linkType]({ url });
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user