0

I have a link like

<a class="nav-link" data-toggle="modal" data-target="#testModal" @click="platform.os.family == 'iOS' ? showSettingiOS() : showSetting()">Test</a>

I want to add if statement based on device & change function name. I have tried as

@click="platform.os.family == 'iOS' ? showSettingiOS() : showSetting()"

and

@click="platform.os.family == 'iOS' ? 'showSettingiOS()' : 'showSetting()'"

nothing worked. My platform object not usable inside function this is why I am trying using at href. What I am doing wrong

5
  • What is platform meant to be? Commented Jan 14, 2019 at 5:01
  • 1
    I am using npmjs.com/package/platform for detecting platform Commented Jan 14, 2019 at 5:03
  • Ok, so how are you assigning it to your Vue / component instance's platform property for use in the template? Commented Jan 14, 2019 at 5:21
  • 1
    Also, what do you mean by "My platform object not usable inside function"? Commented Jan 14, 2019 at 5:24
  • @Phil Thanks for your effort. I have found a solution. However platform was loaded in parent component but not working in iOS only Commented Jan 14, 2019 at 5:26

2 Answers 2

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' ]
}
Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.