JavaScript/vue.js/标签属性:修订间差异
来自康健生活
| 第22行: | 第22行: | ||
) | ) | ||
}"</syntaxhighlight> | }"</syntaxhighlight> | ||
== style == | |||
== class == | |||
<syntaxhighlight lang="html5"> | |||
<li v-for="(item,index) in items" :class="{'active':item.checked}" @click="isActive(item)">{{item.text}}</li> | |||
<script> | |||
methods: { | |||
isActive: function(item) { | |||
//方法1 | |||
if (typeof item.checked == 'undefined') { | |||
//全局创建 | |||
//Vue.set(item,'checked',true); | |||
//局部创建 | |||
this.$set(item, 'checked', true); | |||
// console.log(item.text) | |||
} else { | |||
item.checked = !item.checked; | |||
} | |||
//方法2 | |||
this.$set(item, 'checked', !item.checked); | |||
} | |||
} | |||
} | |||
</script> | |||
</syntaxhighlight> | |||