我正在尝试测试,但是有一个我找不到解决方案的问题,这是我的测试。我知道不是很好,但是我需要解决方案。
这是我的方法:
import { Meteor } from 'meteor/meteor'
import { ValidatedMethod } from 'meteor/mdg:validated-method'
import { CallPromiseMixin } from 'meteor/didericis:callpromise-mixin'
import Journal from '../journals/journals'
import JournalDetails from '../journals/journal-details'
export const journalMigrateTotDecimal = new ValidatedMethod({
name: 'app.journalMigrateTotDecimal',
mixins: [CallPromiseMixin],
validate: null,
async run() {
if (Meteor.isServer) {
let res
console.log('start....');
let journals = await Journal.find().lean()
res = await Journal.deleteMany({})
res = await Journal.insertMany(journals)
console.log('done journal!');
let journalDetails = await JournalDetails.find().lean()
res = await JournalDetails.deleteMany({})
res = await JournalDetails.insertMany(journalDetails)
console.log('done journal details!');
return res
}
},
})
致电客户
<ElButton type="primary" @click="migrateJournalData">
Journal
</ElButton>
methods: {
migrateJournalData() {
this.loading = true
journalMigrateTotDecimal
.callPromise()
.then(res => {
this.loading = false
console.log('res', res)
})
.catch(err => {
this.loading = false
console.log('err', err)
})
},
},
问题在于方法被多次调用,我不知道为什么。我不知道该怎么解决。