javascript - VueJS v-bind not working with kebab-case - Stack Overflow

I am working on a task list with Vue.JS (like everyone) and I've managed to add a task, show the t

I am working on a task list with Vue.JS (like everyone) and I've managed to add a task, show the tasks and even to delete the tasks. After that I was working on checking tasks and give them a class for success.

So I thought, if I have a data like class set to false, and use this line of code:

<div v-for="(task, index) in tasks" class="panel panel-default" :class="{panel-success: task.class}" :key="task">

I could set the class to true with a click event and give the particular class of panel-success (from bootstrap).

When I was doing that, I came up to the following problem:

avoid using JavaScript keyword as property name: "class" in expression :class="{panel-success: task.class}"

The problem was, the kebab case syntax of panel-success. When I changed the name to panelsuccess it was working. Why is kebab case not working?

I am working on a task list with Vue.JS (like everyone) and I've managed to add a task, show the tasks and even to delete the tasks. After that I was working on checking tasks and give them a class for success.

So I thought, if I have a data like class set to false, and use this line of code:

<div v-for="(task, index) in tasks" class="panel panel-default" :class="{panel-success: task.class}" :key="task">

I could set the class to true with a click event and give the particular class of panel-success (from bootstrap).

When I was doing that, I came up to the following problem:

avoid using JavaScript keyword as property name: "class" in expression :class="{panel-success: task.class}"

The problem was, the kebab case syntax of panel-success. When I changed the name to panelsuccess it was working. Why is kebab case not working?

Share edited Apr 5, 2017 at 14:48 Giesburts asked Apr 5, 2017 at 14:45 GiesburtsGiesburts 7,67616 gold badges52 silver badges92 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

The value for :class is a Javascript object, and in Javascript objects a kebab-case identifier is not valid, that's why you're having that error. For it to work, simply wrap your kebab-case identifier around single quotes:

:class="{'panel-success': task.class}"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744907795a4600361.html

相关推荐

  • javascript - VueJS v-bind not working with kebab-case - Stack Overflow

    I am working on a task list with Vue.JS (like everyone) and I've managed to add a task, show the t

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信