Skip to content

Commit 45976e7

Browse files
committed
perf: data vm
1 parent beeb2c3 commit 45976e7

8 files changed

Lines changed: 86 additions & 59 deletions

File tree

components/ly-markdown/ly-markdown.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@
3838
components: {
3939
uParse
4040
},
41-
data: function () {
41+
data: function() {
4242
return {
4343
screenHeight: 0,
4444
cursor: 0,
45-
textareaDataSync:this.textareaData,
46-
textareaHtmlSync:this.textareaHtml
45+
textareaDataSync: '',
46+
textareaHtmlSync: ''
4747
}
4848
},
4949
props: {
5050
textareaData: {
5151
type: String,
52-
default: ""
52+
default: ''
5353
},
5454
textareaHtml: {
5555
type: String,
56-
default: ""
56+
default: ''
5757
},
5858
showPreview: {
5959
type: Boolean,
@@ -74,7 +74,7 @@
7474
// #ifdef MP-WEIXIN
7575
uni.setClipboardData({
7676
data: href,
77-
success: function () {
77+
success: function() {
7878
uni.showModal({
7979
content: "网址已复制,请在浏览器中粘贴打开",
8080
showCancel: false
@@ -154,13 +154,17 @@
154154
}
155155
},
156156
watch: {
157-
"textareaDataSync": function (newValue, oldValue) {
157+
"textareaDataSync": function(newValue, oldValue) {
158158
this.textareaHtmlSync = marked(newValue)
159159
this.$emit('update:textareaData', newValue)
160160
this.$emit('update:textareaHtml', this.textareaHtmlSync)
161161
}
162162
},
163-
mounted: function () {
163+
created() {
164+
this.textareaDataSync = this.textareaData;
165+
this.textareaHtmlSync = this.textareaHtml;
166+
},
167+
mounted() {
164168
uni.getSystemInfo({
165169
success: res => {
166170
this.screenHeight = res.screenHeight
@@ -217,4 +221,4 @@
217221
.input-content {
218222
min-height: ;
219223
}
220-
</style>
224+
</style>

components/qrcode/qrcode.vue

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<view class="qrcode">
3-
<image class="image" v-if="img" :src="img" :style="{width: sizySync + 'px', height: sizySync + 'px'}"/>
3+
<image class="image" v-if="img" :src="img" :style="{width: sizeSync + 'px', height: sizeSync + 'px'}" />
44
</view>
55
</template>
66
<script>
@@ -12,45 +12,48 @@
1212
type: String,
1313
default: ''
1414
},
15-
size:{
16-
type:Number,
17-
default:100
15+
size: {
16+
type: Number,
17+
default: 100
1818
}
1919
},
20-
data(){
21-
return{
20+
data() {
21+
return {
2222
img: '',
23-
sizySync: this.size
23+
sizeSync: 100
2424
}
2525
},
2626
methods: {
27-
creatQrcode(){
27+
creatQrcode() {
2828
let val = this.val + '';
29-
if(!val){
29+
if (!val) {
3030
return;
3131
}
3232
let img = QR.createQrCodeImg(val, {
3333
size: parseInt(this.size)
3434
});
3535
this.img = img;
3636
},
37-
clearQrcode(){
37+
clearQrcode() {
3838
this.img = '';
3939
}
4040
},
41-
watch:{
42-
size(newVal, oldVal){
43-
if(newVal != oldVal){
44-
this.sizySync = newVal;
41+
watch: {
42+
size(newVal, oldVal) {
43+
if (newVal != oldVal) {
44+
this.sizeSync = newVal;
4545
this.creatQrcode();
4646
}
4747
}
48+
},
49+
created() {
50+
this.sizeSync = this.size;
4851
}
4952
}
5053
</script>
5154
<style>
52-
.qrcode{
55+
.qrcode {
5356
display: flex;
5457
justify-content: center;
5558
}
56-
</style>
59+
</style>

components/uni-collapse-item/uni-collapse-item.vue

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,15 @@
2626
components: {
2727
uniIcon
2828
},
29-
data() {
30-
const elId = `Uni_${Math.ceil(Math.random() * 10e5).toString(36)}`
31-
return {
32-
isOpen: this.open,
33-
height: 0,
34-
elId: elId
35-
};
36-
},
37-
watch: {
38-
open(val) {
39-
this.isOpen = val
40-
}
41-
},
4229
props: {
4330
animation: { //动画效果:inner内容动;outer容器动
4431
type: String,
4532
default: 'outer'
4633
},
47-
title: String, //列表标题
34+
title: { //列表标题
35+
type: String,
36+
default: ''
37+
},
4838
name: { //唯一标识符
4939
type: [Number, String],
5040
default: 0
@@ -57,11 +47,28 @@
5747
type: [Boolean, String],
5848
default: false
5949
},
60-
thumb: String //缩略图
50+
thumb: { //缩略图
51+
type: String,
52+
default: ''
53+
}
54+
},
55+
data() {
56+
const elId = `Uni_${Math.ceil(Math.random() * 10e5).toString(36)}`
57+
return {
58+
isOpen: false,
59+
height: 0,
60+
elId: elId
61+
};
62+
},
63+
watch: {
64+
open(val) {
65+
this.isOpen = val
66+
}
6167
},
6268
created() {
6369
let parent = this.$parent || this.$root
6470
let name = parent.$options.name
71+
this.isOpen = this.open
6572
6673
while (parent && name !== 'uni-collapse') {
6774
parent = parent.$parent

components/uni-number-box/uni-number-box.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
data() {
3434
return {
35-
inputValue: +this.value
35+
inputValue: 0
3636
}
3737
},
3838
watch: {
@@ -85,6 +85,9 @@
8585
}
8686
this.inputValue = value
8787
}
88+
},
89+
created() {
90+
this.inputValue = +this.value;
8891
}
8992
}
9093
</script>

components/uni-pagination/uni-pagination.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<script>
2828
import uniIcon from '../uni-icon/uni-icon.vue'
2929
export default {
30-
name: "uni-pagination",
30+
name: 'uni-pagination',
3131
components: {
3232
uniIcon
3333
},
@@ -59,12 +59,12 @@
5959
},
6060
watch: {
6161
current(val) {
62-
this.currentIndex = Number(val)
62+
this.currentIndex = +val
6363
}
6464
},
6565
data() {
6666
return {
67-
currentIndex: Number(this.current)
67+
currentIndex: 1
6868
}
6969
},
7070
computed: {
@@ -99,6 +99,9 @@
9999
current: this.currentIndex
100100
})
101101
}
102+
},
103+
created() {
104+
this.currentIndex = +this.current;
102105
}
103106
}
104107
</script>

components/uni-popup/uni-popup.vue

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<view>
33
<view class="uni-mask" v-show="show" :style="{ top: offsetTop + 'px' }" @click="hide" @touchmove.stop.prevent="moveHandle"></view>
4-
<view class="uni-popup" :class="['uni-popup-' + position, 'uni-popup-' + mode]" v-show="show">
4+
<view class="uni-popup" :class="'uni-popup-' + position + ' ' + 'uni-popup-' + mode" v-show="show">
55
{{ msg }}
66
<slot></slot>
77
<view v-if="position === 'middle' && mode === 'insert'" class=" uni-icon uni-icon-close" :class="{
@@ -58,21 +58,12 @@
5858
}
5959
},
6060
data() {
61-
let offsetTop = 0;
62-
//#ifdef H5
63-
if (!this.h5Top) {
64-
offsetTop = 44;
65-
} else {
66-
offsetTop = 0;
67-
}
68-
//#endif
6961
return {
70-
offsetTop: offsetTop
62+
offsetTop: 0
7163
};
7264
},
7365
watch: {
7466
h5Top(newVal) {
75-
console.log(newVal);
7667
if (newVal) {
7768
this.offsetTop = 44;
7869
} else {
@@ -81,7 +72,7 @@
8172
}
8273
},
8374
methods: {
84-
hide: function() {
75+
hide() {
8576
if (this.mode === 'insert' && this.position === 'middle') return;
8677
this.$emit('hidePopup');
8778
},
@@ -91,6 +82,17 @@
9182
}
9283
},
9384
moveHandle() {}
85+
},
86+
created() {
87+
let offsetTop = 0;
88+
//#ifdef H5
89+
if (!this.h5Top) {
90+
offsetTop = 44;
91+
} else {
92+
offsetTop = 0;
93+
}
94+
//#endif
95+
this.offsetTop = offsetTop;
9496
}
9597
};
9698
</script>

components/uni-rate/uni-rate.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
},
6161
data() {
6262
return {
63-
maxSync: this.max,
64-
valueSync: this.value
63+
valueSync: ''
6564
};
6665
},
6766
computed: {
@@ -98,6 +97,9 @@
9897
value: this.valueSync
9998
});
10099
}
100+
},
101+
created() {
102+
this.valueSync = this.value;
101103
}
102104
};
103105
</script>

components/uni-segmented-control/uni-segmented-control.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
},
4242
data() {
4343
return {
44-
currentIndex: this.current
44+
currentIndex: 0
4545
};
4646
},
4747
watch: {
@@ -58,6 +58,9 @@
5858
this.$emit('clickItem', index);
5959
}
6060
}
61+
},
62+
created() {
63+
this.currentIndex = this.current;
6164
}
6265
};
6366
</script>

0 commit comments

Comments
 (0)