Home > Software engineering >  Check URL $route param value using v-if in vue js
Check URL $route param value using v-if in vue js

Time:03-15

How can I check the meta value of my url using v-if in vue.js ?

Assuming that i have this url : http://127.0.0.1:8000/setting

And I want to make condition in my v-app like this :

<v-app v-if="(if 'setting' is in the url)">

CodePudding user response:

<v-app v-if="url.indexOf('http://127.0.0.1:8000/setting') > -1 ? true : false">

if there it is inclue 'http://127.0.0.1:8000/setting' return true

else return false

CodePudding user response:

Well,I would create a property in data(), like this:

data() {
 urlHasSetting: false
}

in my created() lifecycle method I would check:

var parts = window.location.href.split("/")
var hasSetting = parts.filter("settings")[0]

if (hasSettings) this.urlHasSetting = true

and you will need to create a computed that return urlHasSetting data.

computed: {
  settingComputed() {
    return this.urlHasSetting
  }
}

and you will be able to use your settingComputed in your v-if

  • Related