coolair
V2EX  ›  问与答

微信小程序的 scroll-into-view="{{toView}}"是不是直接写在 data 里无效啊?

  •  
  •   coolair · Jul 7, 2019 · 2921 views
    This topic created in 2504 days ago, the information mentioned may be changed or developed.

    直接这样没有用:

    Page({
      data: {
        toView: 'item-3'
      },
    })
    

    这样的话才有用:

    Page({
      data: {
        toView: 'item-3'
      },
      onLoad: function (options) {
        this.setData({
            toView: 'item-3'
        })
      },
    })
    

    我看一本教程里面直接就是写在 data 里,然后说“第一次渲染时,<scroll-view>默认滚动到 id 值为 item-3 区域”,但是,我这样写,并没有滚动到 item-3,如果再 onLoad 里改变 toView 的值,才会滚动,是这样的吗?</scroll-view>

    1 replies    2019-07-07 13:13:54 +08:00
    Sornets
        1
    Sornets  
       Jul 7, 2019
    this.setData 以后变量在模板里生效
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3863 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 04:29 · PVG 12:29 · LAX 21:29 · JFK 00:29
    ♥ Do have faith in what you're doing.