Commit b45c23a0 by 张立顺

新增功能

1 parent 515d0de8
## 正式版appid wx2c28337db96364d2
## 体验版appid wx24ebae5768e74138
# computed和watch方法使用
#### computed和watch方法使用
先导入并混合
```
// 注意: computed 函数中不能访问 this ,只有 data 对象可供访问
```
```js
// 导入方法
import { behavior as computedBehavior } from '~/utils/lib/miniprogram-computed'
// 混入
behaviors: [computedBehavior],
// 使用
computed: {
test(data) {
return data.bgUrl + data.test
}
},
// 默认已深度监听
watch: {
'test, pages': function (a, b) {
console.log(a)
// this.setData({
// sum: a + b,
// })
}
},
```
......@@ -3,7 +3,7 @@ import mineApi from '~/api/mineApi/index'
// import USERAPI from '~/api/usersApi/index'
import { IMG_URL } from '~/utils/constantData'
// console.log(IMG_URL)
import { behavior as computedBehavior } from '~/utils/lib/miniprogram-computed'
// import { behavior as computedBehavior } from '~/utils/lib/miniprogram-computed'
const listObj = Object.freeze([
{
......@@ -62,7 +62,7 @@ const listObj = Object.freeze([
}
])
Component({
behaviors: [computedBehavior],
// behaviors: [computedBehavior],
options: {
addGlobalClass: true
},
......@@ -97,31 +97,31 @@ Component({
this.getMerchantCustomInfoList()
this.testFn()
},
computed: {
test(data) {
return data.bgUrl + data.pageNum
}
},
watch: {
'testData, pages': function (a, b) {
console.log(a)
// this.setData({
// sum: a + b,
// })
}
},
// computed: {
// test(data) {
// return data.bgUrl + data.pageNum
// }
// },
// watch: {
// 'test, pages': function (a, b) {
// console.log(a)
// // this.setData({
// // sum: a + b,
// // })
// }
// },
/**
* 组件的方法列表
*/
methods: {
testFn() {
// let {}
// testFn() {
// // let {}
let name = `testData[0].a`
this.setData({
[name]: 2
})
},
// let name = `testData[0].a`
// this.setData({
// [name]: 2
// })
// },
restPageNum() {
console.log('restPageNum')
this.setData({
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!