如何給小程序data數據中的對象中的某個屬性賦值

1、如何給小程序data數據中的對象中的某個屬性賦值

2、比如userCrad對象中的屬性是輸入框input獲取的用離開焦點事件bindblur="bindblur"拿到input的值value   

 

data: {

    userCrad:{

      photoUrl:'',

      name:'',

      phone:'',

      companyName:'',

      job:'',

      email:'',

      wxName:'',

      companyAddress:''

    }

  },

  // input更新userCrad值  這樣就可以賦值了

  bindblur(e){

    let type = e.currentTarget.dataset.type  //爲userCrad對象的屬性名photoUrl/name/phone等

    let val = e.detail.value

    let name = `userCrad.${type}` //重點在這裏 userCrad.name最爲key

    this.setData({

        [name]: val

    })

 

 

  },

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章