Array destructuring in JavaScript

前端 未结 5 621
情歌与酒
情歌与酒 2020-11-30 12:21

I have this code in my vue-js app:

methods: {
    onSubmit() {
      ApiService.post(\'auth/sign_in\', {
        email: this.email,
        password: this.pa         


        
5条回答
  •  时光取名叫无心
    2020-11-30 12:34

    U can rewrite that line as [this.message] = res.response.data.errors; and that es-lint error will go off. See this example for better understanding

    var x = {
      y: {
        z: {
          w: [3, 4]
        }
      }
    };
    
    function foo() {
      [this.a] = x.y.z.w
      console.log(this.a);
    }
    foo() // prints 3

    For more information about array destructuring please see here

提交回复
热议问题