1 回答

TA貢獻(xiàn)1921條經(jīng)驗(yàn) 獲得超9個(gè)贊
一個(gè)很好的用例Set:使self.working成為一個(gè)Set對(duì)象,并向其添加/刪除值。
Set 就像一個(gè)數(shù)組,但它沒有順序。
export default {
data: function() {
return {
working: new Set()
}
},
methods: {
respondToClickA: function() {
let self = this;
if(!self.working.has('a'))
{
self.working.add('a')
axios.get('/ajax')
.then(function(response){
self.working.delete('a');
});
}
},
respondToClickB: function() {
let self = this;
if(!self.working.has('b'))
{
self.working.add('b');
axios.get('/ajax')
.then(function(response){
self.working.delete('b');
});
}
}
}
}
添加回答
舉報(bào)