Commit b45c23a0 by 张立顺

新增功能

1 parent 515d0de8
## 正式版appid wx2c28337db96364d2 ## 正式版appid wx2c28337db96364d2
## 体验版appid wx24ebae5768e74138 ## 体验版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' ...@@ -3,7 +3,7 @@ import mineApi from '~/api/mineApi/index'
// import USERAPI from '~/api/usersApi/index' // import USERAPI from '~/api/usersApi/index'
import { IMG_URL } from '~/utils/constantData' import { IMG_URL } from '~/utils/constantData'
// console.log(IMG_URL) // 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([ const listObj = Object.freeze([
{ {
...@@ -62,7 +62,7 @@ const listObj = Object.freeze([ ...@@ -62,7 +62,7 @@ const listObj = Object.freeze([
} }
]) ])
Component({ Component({
behaviors: [computedBehavior], // behaviors: [computedBehavior],
options: { options: {
addGlobalClass: true addGlobalClass: true
}, },
...@@ -97,31 +97,31 @@ Component({ ...@@ -97,31 +97,31 @@ Component({
this.getMerchantCustomInfoList() this.getMerchantCustomInfoList()
this.testFn() this.testFn()
}, },
computed: { // computed: {
test(data) { // test(data) {
return data.bgUrl + data.pageNum // return data.bgUrl + data.pageNum
} // }
}, // },
watch: { // watch: {
'testData, pages': function (a, b) { // 'test, pages': function (a, b) {
console.log(a) // console.log(a)
// this.setData({ // // this.setData({
// sum: a + b, // // sum: a + b,
// }) // // })
} // }
}, // },
/** /**
* 组件的方法列表 * 组件的方法列表
*/ */
methods: { methods: {
testFn() { // testFn() {
// let {} // // let {}
let name = `testData[0].a` // let name = `testData[0].a`
this.setData({ // this.setData({
[name]: 2 // [name]: 2
}) // })
}, // },
restPageNum() { restPageNum() {
console.log('restPageNum') console.log('restPageNum')
this.setData({ this.setData({
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!