npm i mp-computed
in your page's js file
const { createReactive } = require('mp-computed')
Page({
onLoad() {
createReactive.call(this)
},
data: {
name: 'stranger'
},
computed: {
sayHi() {
return `hello! ${this.data.name}`
}
},
changeName() {
this.setData({ name: 'nicong622' })
}
})
in your page's wxml file
<view>{{sayHi}}</view>
<button bindtap="changeName">change name</button>