Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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.js将类绑定到组件模板_Javascript_Vue.js - Fatal编程技术网

Javascript Vue.js将类绑定到组件模板

Javascript Vue.js将类绑定到组件模板,javascript,vue.js,Javascript,Vue.js,我希望能够根据一个条件将一个类绑定到我的组件模板上,但也要应用一个始终存在的默认类 这是我的代码,到目前为止,我能够让它在满足条件时应用currentmount类,但不能应用event\u month类。我是否使用了正确的语法 const listTemplate=''+ '' + '' + “{{month}}”+ '' + ''; Vue.component('events-list-view'{ 模板:listTemplate, 数据(){ 返回{ 月份:[“一月”、“二月”、“三月”、

我希望能够根据一个条件将一个类绑定到我的组件模板上,但也要应用一个始终存在的默认类

这是我的代码,到目前为止,我能够让它在满足条件时应用currentmount类,但不能应用event\u month类。我是否使用了正确的语法

const listTemplate=''+
'' +
'' +
“{{month}}”+
'' +
'';
Vue.component('events-list-view'{
模板:listTemplate,
数据(){
返回{
月份:[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”],
currentMonth:新日期().getMonth(),
};
},
});
新的Vue({el:#app})

在上述代码中,您将event\u month绑定到所有12个div节点,但其中只有一个节点将与当前类绑定。
但您的问题不清楚,请您详细说明。

只需将
事件月
修改为
事件月

const listTemplate = '' +
'<div class="list_body">' +
    '<div v-for="(month, index) in formattedEvents" v-if="month.length" v-bind:class="[\'event_month\', {current : index === currentMonth}]">' +
    '</div>' +
'</div>';
const listTemplate=''+
'' +
'' +
'' +
'';

event\u month
被编译为实例属性。

问题是event\u month没有绑定到所有12个节点。我修正了我的问题,以便更清楚地说明这一点