Here is my Vue component code:
<template>
<ul class="nav nav-tabs nav-tabs-bg">
<li v-for="tab in tabs" role="presentation" :class="setActive(tab.url)">
<a :href="baseUrl + tab.url">{{tab.title}}</a>
</li>
</ul>
</template>
<script>
export default {
props: ['shop'],
data() {
return{
tabs: [
{
title: 'product',
url: '/store/' + this.shop.id + '/' + strSlug(this.shop.name)
},
{
title: 'info',
url: '/store/' + this.shop.id + '/' + strSlug(this.shop.name) + '/info'
}
]
}
},
methods: {
setActive(pathname){
return {active: window.location.pathname == pathname}
},
strSlug: function(val) {
return _.kebabCase(val)
}
}
}
</script>
When running the code, an error occurs as follows:
[Vue warn]: Error in data(): "ReferenceError: strSlug is not defined"
After console.logging(window.location.pathname), the output is:
/store/21/chelsea-hazard-store
The goal is to highlight tabs that match the current URL
To achieve this, a method called strSlug is used to convert text into kebab case
However, it seems there is an issue with calling the method from within the data section
How can I fix this error?