logic-helper
Version:
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
31 lines (29 loc) • 687 B
JavaScript
import Immutable from 'immutable';
export default class{
constructor(){
this.records = [];
this.index = 0;
}
setData(data){
if(this.index!=this.records.length-1){
this.records = this.records.slice(0,this.index+1);
}
this.records.push(Immutable.fromJS(data));
this.index = this.records.length-1;
}
getData(){
return this.records[this.index].toJS();
}
prev(){
if(this.index>0){
this.index--;
}
return this.getData();
}
next(){
if(this.index<this.records.length-1){
this.index++;
}
return this.getData();
}
}