Vue 1.0.4 js gives error on class binding: Uncaught TypeError: Cannot read property 'get' of undefined
Vue 1.0.4 js gives error on class binding: Uncaught TypeError: Cannot read property 'get' of undefined
我是Vue的新手,我尝试做一个小的PoC,但我不知道为什么,我得到了一个错误:Uncaught TypeError: Cannot read 属性 'get' 未定义.
我的html:
<div id="configuration">
....
<div class="list-group config-list">
<a
v-for="item in configurationList"
v-on:click="SelectItem(item)"
class="list-group-item"
v-bind:class="'active': isActive(item)"
href="#">{{ FormatItemType(item) }}
</a>
</div>
....
</div>
Vue 定义:
new Vue({
el: "#configuration",
data:
{
configurationList:
[
{ Id: "100", Version: 1, Type: "TestType.TestType100" },
{ Id: "200", Version: 2, Type: "TestType.TestType200" },
{ Id: "300", Version: 3, Type: "TestType.TestType300.Roles" }
],
configurationData:
{
Id: "100", Version: 1, Type: "TestType.TestType100", Content: "TestType.TestType100"
},
computed:
{
isActive: function (configurationListItem)
{
return choosenConfigurationListItem.Type == configurationListItem.Type;
}
},
choosenConfigurationListItem: null
},
methods:
{
FormatItemType: ... not important
SelectItem: function (configurationListItem)
{
this.choosenConfigurationListItem = configurationListItem;
}
}
})
如果我删除 v-bind:class="'active': isActive(item)" 条目,没有错误。是语法错误,还是遗漏了什么?
提前致谢,
雷管
你试过 :class="{active: isActive(item)}" 语法吗?
我是Vue的新手,我尝试做一个小的PoC,但我不知道为什么,我得到了一个错误:Uncaught TypeError: Cannot read 属性 'get' 未定义.
我的html:
<div id="configuration">
....
<div class="list-group config-list">
<a
v-for="item in configurationList"
v-on:click="SelectItem(item)"
class="list-group-item"
v-bind:class="'active': isActive(item)"
href="#">{{ FormatItemType(item) }}
</a>
</div>
....
</div>
Vue 定义:
new Vue({
el: "#configuration",
data:
{
configurationList:
[
{ Id: "100", Version: 1, Type: "TestType.TestType100" },
{ Id: "200", Version: 2, Type: "TestType.TestType200" },
{ Id: "300", Version: 3, Type: "TestType.TestType300.Roles" }
],
configurationData:
{
Id: "100", Version: 1, Type: "TestType.TestType100", Content: "TestType.TestType100"
},
computed:
{
isActive: function (configurationListItem)
{
return choosenConfigurationListItem.Type == configurationListItem.Type;
}
},
choosenConfigurationListItem: null
},
methods:
{
FormatItemType: ... not important
SelectItem: function (configurationListItem)
{
this.choosenConfigurationListItem = configurationListItem;
}
}
})
如果我删除 v-bind:class="'active': isActive(item)" 条目,没有错误。是语法错误,还是遗漏了什么?
提前致谢, 雷管
你试过 :class="{active: isActive(item)}" 语法吗?