微信小程序怎么在一页面js部分数据互传

img

img


我还加了个wx:if,麻烦你帮我看看哪错了,实在不知道了;

img

img


这个是我的第二步,赋新值

img


这是第三步,调用this.data.num1
第四步,重新渲染是不是利用wx:if就可以呢

js里调用页面的data?函数参数里传递this,可以调用到

// utils/demo.js
export const demoFunc = function(that) {
  console.log(that.data);
}

// 页面
import { demoFunc } from '../../utils/demo'

Page({
  data: {
    num: 1
  },
  onShow() {
    demoFunc(this)
  }
})

那个报错有对应的行数了哇,注释一下,试试