微信小程序设置对象参数

 顺带一提:微信小程序是不能直接连接数据库的,所以想要获取数据库的真实地址是要通过访问接口来实现的。

1.微信小程序设置普通参数:

 data: {
      abc: "",
      qwe: "",
  },
  onLoad: function (options) {
    var self = this
        self.setData({
          abc: options.a
          qwe: options.b
        })
      }
   

2.设置对象参数

 data: {
info:{
      abc: ""
}
  },
  onLoad: function (options) {
    var self = this
    var abcd = 'info.abc'
        self.setData({
          [abcd]: options.a
        })
      }
   

也可以直接写:

 data: {
info:{
      abc: ""
}
  },
  onLoad: function (options) {
    var self = this
        self.setData({
          'info.abc': options.a
        })
      }
   

猜你喜欢

转载自blog.csdn.net/qq_39404258/article/details/90291465