[Vuejs]-Vuejs use if statement inside @click event

0👍

It is fixed finally. I use

computed: {
    platform: () => platform,
},

at my component hooks & working fine now. However without it platform working everywhere but not working on only in iOS webview.

3👍

For complex, conditional logic, you should probably use a method instead of relying on inline evaluation:

<a class="nav-link" data-toggle="modal" data-target="#testModal" @click="click">Test</a>
methods: {
  click() {
    if (this.platform.os.family === 'iOS') {
      this.showSettingiOS();
    } 
    else {
      this.showSetting();
    }
  },

  showSettingiOS() {
    
  },
  showSetting() {
    
  }
}

Edit

If the instance of platform is of the parent’s, you could provide it to the child component:

// Parent
{
  provide() {
    return {
      platform
    }
  }
}

// Child    
{
  inject: [ 'platform' ]
}
👤Yom T.

Leave a comment