使用方法arguments和this.data的最佳实践



想知道在vue方法中传递参数和使用this.localData的数据或道具引用之间的最佳实践是什么?

拥有这样的模板

<div @click="close_tab"/>
<span>
{{ tabInstance.count }}
</span>
</div>
close_tab(id, isCurrentTab) {
if (isCurrentTab) {
this[REMOVE_CURRENT_TAB]();
this.$router.push({ name: 'home' });
} else {
this[REMOVE_TAB](id);
}
},

// or below
close_tab() {
if (this.isCurrentTab) {
this[REMOVE_CURRENT_TAB]();
this.$router.push({ name: 'home' });
} else {
this[REMOVE_TAB](this.tab.id);
}
},

这取决于您的使用上下文。如果您不想将close_tabthis.tab.idthis.isCurrentTab以外的其他值一起使用,则不应该以参数样式编写方法。

相关内容

最新更新