我的Vue组件如下:
<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>
如果代码运行,就会出现以下错误:
[Vue warn]: Error in data(): "ReferenceError: strSlug is not defined"
如果我 console.log(window.location.pathname),结果如下 :
/store/21/chelsea-hazard-store
所以,如果它与选项卡中的数据相同,则会激活
我调用 strSlug 方法将每个转换为小写并将空格转换为 -
似乎无法从数据中调用该方法
我该如何解决这个错误?