Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 设置一个行项目';主动';在vue中的某个时间_Javascript_Vue.js - Fatal编程技术网

Javascript 设置一个行项目';主动';在vue中的某个时间

Javascript 设置一个行项目';主动';在vue中的某个时间,javascript,vue.js,Javascript,Vue.js,我在vue模板中有一个小的无序列表: <ul style="border-bottom:none !important; text-decoration:none"> <li class="commentToggle" v-bind:class="{active:commentActive}" v-on:click="setInputName('new')">New Comment</li> <li class="commentTog

我在vue模板中有一个小的无序列表:

<ul style="border-bottom:none !important; text-decoration:none">
     <li class="commentToggle" v-bind:class="{active:commentActive}" v-on:click="setInputName('new')">New Comment</li>
     <li class="commentToggle" v-bind:class="{active:commentActive}" v-on:click="setInputName('note')">Note</li>
</ul>

这是功能性的,但当我点击其中一个时,它显然会将两个输入都设置为活动。如何更改此选项以仅将单击的行项目设置为活动?

您需要使用唯一标识符来确定哪个注释处于活动状态。以最基本的方式使用当前设置:

<li class="commentToggle" 
        v-bind:class="{active:commentActive === 'new'}" 
        v-on:click="setInputName('new')">
    New Comment
</li>
<li class="commentToggle" 
        v-bind:class="{active:commentActive === 'note'}" 
        v-on:click="setInputName('note')">
    Note
</li>

我们所做的调整是为了确保
commentActive
与我们使用的
str
匹配。您可以将该标识符更改为其他任何内容,如果您愿意,还可以传递其他参数。

当然,这现在是有意义的。我很感激,我想有时候我会试图用vue来过度复杂化。谢谢
<li class="commentToggle" 
        v-bind:class="{active:commentActive === 'new'}" 
        v-on:click="setInputName('new')">
    New Comment
</li>
<li class="commentToggle" 
        v-bind:class="{active:commentActive === 'note'}" 
        v-on:click="setInputName('note')">
    Note
</li>
setInputName(str) {
  this.inputName = str;
  this.commentActive = str;
},