mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
perf(button): use wxs instead of setData (#3839)
This commit is contained in:
parent
ca08409488
commit
979dc506bf
@ -50,32 +50,7 @@ VantComponent({
|
||||
type: String,
|
||||
value: '20px',
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
observer(color: string) {
|
||||
let style = '';
|
||||
|
||||
if (color) {
|
||||
style += `color: ${this.data.plain ? color : 'white'};`;
|
||||
|
||||
if (!this.data.plain) {
|
||||
// Use background instead of backgroundColor to make linear-gradient work
|
||||
style += `background: ${color};`;
|
||||
}
|
||||
|
||||
// hide border when color is linear-gradient
|
||||
if (color.indexOf('gradient') !== -1) {
|
||||
style += 'border: 0;';
|
||||
} else {
|
||||
style += `border-color: ${color};`;
|
||||
}
|
||||
}
|
||||
|
||||
if (style !== this.data.baseStyle) {
|
||||
this.setData({ baseStyle: style });
|
||||
}
|
||||
},
|
||||
},
|
||||
color: String,
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
@ -1,4 +1,5 @@
|
||||
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||
<wxs src="./index.wxs" module="computed" />
|
||||
|
||||
<button
|
||||
id="{{ id }}"
|
||||
@ -7,7 +8,7 @@
|
||||
hover-class="van-button--active hover-class"
|
||||
lang="{{ lang }}"
|
||||
form-type="{{ formType }}"
|
||||
style="{{ baseStyle }} {{ customStyle }}"
|
||||
style="{{ computed.rootStyle({ plain, color }) }} {{ customStyle }}"
|
||||
open-type="{{ disabled ? '' : openType }}"
|
||||
business-id="{{ businessId }}"
|
||||
session-from="{{ sessionFrom }}"
|
||||
@ -30,7 +31,7 @@
|
||||
custom-class="loading-class"
|
||||
size="{{ loadingSize }}"
|
||||
type="{{ loadingType }}"
|
||||
color="{{ loadingColor(type,color,plain) }}"
|
||||
color="{{ computed.loadingColor({ type, color, plain }) }}"
|
||||
/>
|
||||
<view wx:if="{{ loadingText }}" class="van-button__loading-text">
|
||||
{{ loadingText }}
|
||||
@ -50,19 +51,3 @@
|
||||
</view>
|
||||
</block>
|
||||
</button>
|
||||
|
||||
|
||||
<wxs module="loadingColor">
|
||||
function get(type, color,plain) {
|
||||
if(plain) {
|
||||
return color ? color: '#c9c9c9';
|
||||
}
|
||||
|
||||
if(type === 'default') {
|
||||
return '#c9c9c9';
|
||||
}
|
||||
return 'white';
|
||||
}
|
||||
|
||||
module.exports = get;
|
||||
</wxs>
|
||||
|
39
packages/button/index.wxs
Normal file
39
packages/button/index.wxs
Normal file
@ -0,0 +1,39 @@
|
||||
/* eslint-disable */
|
||||
var style = require('../wxs/style.wxs');
|
||||
|
||||
function rootStyle(data) {
|
||||
if (!data.color) {
|
||||
return '';
|
||||
}
|
||||
|
||||
var properties = {
|
||||
color: data.plain ? data.color : '#fff',
|
||||
background: data.plain ? null : data.color,
|
||||
};
|
||||
|
||||
// hide border when color is linear-gradient
|
||||
if (data.color.indexOf('gradient') !== -1) {
|
||||
properties.border = 0;
|
||||
} else {
|
||||
properties['border-color'] = data.color;
|
||||
}
|
||||
|
||||
return style(properties);
|
||||
}
|
||||
|
||||
function loadingColor(data) {
|
||||
if (data.plain) {
|
||||
return data.color ? data.color : '#c9c9c9';
|
||||
}
|
||||
|
||||
if (data.type === 'default') {
|
||||
return '#c9c9c9';
|
||||
}
|
||||
|
||||
return '#fff';
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
rootStyle: rootStyle,
|
||||
loadingColor: loadingColor,
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user