[improvement] add link mixin (#750)

This commit is contained in:
neverland 2018-10-12 16:36:57 +08:00 committed by GitHub
parent d0b1127802
commit 606c2896c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 28 deletions

View File

@ -1,33 +1,32 @@
import { link } from '../mixins/link';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
classes: [ classes: [
'num-class',
'desc-class',
'thumb-class', 'thumb-class',
'title-class', 'title-class',
'price-class', 'price-class',
'origin-price-class', 'origin-price-class',
'desc-class',
'num-class'
], ],
mixins: [link],
props: { props: {
tag: String, tag: String,
num: String, num: String,
desc: String, desc: String,
thumb: String, thumb: String,
thumbMode: {
type: String,
value: 'scaleToFill'
},
title: String, title: String,
price: String, price: String,
originPrice: String,
centered: Boolean, centered: Boolean,
lazyLoad: Boolean, lazyLoad: Boolean,
thumbLink: String, thumbLink: String,
linkType: { originPrice: String,
thumbMode: {
type: String, type: String,
value: 'navigateTo' value: 'scaleToFill'
}, },
currency: { currency: {
type: String, type: String,
@ -37,10 +36,7 @@ VantComponent({
methods: { methods: {
onClickThumb() { onClickThumb() {
const { thumbLink } = this.data; this.jumpLink('thumbLink');
if (thumbLink) {
wx[this.data.linkType]({ url: thumbLink });
}
} }
} }
}); });

View File

@ -1,3 +1,4 @@
import { link } from '../mixins/link';
import { VantComponent } from '../common/component'; import { VantComponent } from '../common/component';
VantComponent({ VantComponent({
@ -7,10 +8,11 @@ VantComponent({
'value-class' 'value-class'
], ],
mixins: [link],
props: { props: {
title: null, title: null,
value: null, value: null,
url: String,
icon: String, icon: String,
label: String, label: String,
center: Boolean, center: Boolean,
@ -19,10 +21,6 @@ VantComponent({
clickable: Boolean, clickable: Boolean,
titleWidth: String, titleWidth: String,
customStyle: String, customStyle: String,
linkType: {
type: String,
value: 'navigateTo'
},
border: { border: {
type: Boolean, type: Boolean,
value: true value: true
@ -44,15 +42,5 @@ VantComponent({
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: {
onClick() {
const { url } = this.data;
if (url) {
wx[this.data.linkType]({ url });
}
this.$emit('click');
}
} }
}); });

18
packages/mixins/link.ts Normal file
View 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 });
}
}
}
});