[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';
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');
}
}
});

View File

@ -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
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 });
}
}
}
});